Issue
Here is my code:
My LoginResponse
<?php
namespace App\Http\Responses;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
class LoginResponse implements LoginResponseContract
{
/**
* @param $request
* @return mixed
*/
public function toResponse($request)
{
return response()->json([
'resp' => "success"
],200);
}
}
FortifyServiceProviders
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Laravel\Fortify\Fortify;
use App\Http\Responses\LoginResponse;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) {
$email = (string) $request->email;
return Limit::perMinute(15)->by($email.$request->ip());
});
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
}
This keeps returning {two-factor:false}
I have also tried by updating fortify login response on FortifyServiceProvider's register method
as: (this one was totally different and before LoginResponse class was created)
public function register()
{
$this->app->instance(LoginResponse::class, new class implements LoginResponse {
public function toResponse($request)
{
return response()->json([
'resp' => 'success'
],200);
}
});
}
But, still on login, I am receiving this response, {two-factor: false}
, what am I missing and where should I update so that I could get the correct login response on fortify. I am using fortify and sanctum for the laravel spa.
Solution
Not sure what was wrong, but you could follow this procedure to check if this actually works.
Basically, what you have done is correct this is how you could find the bug.
Instead of writing that line on
FortifyServiceProvider
, write it onAppServiceProvider's
boot method.If it works,(and should be), you should confirm if you set up the
Fortify
correctly, you should go through each of those lines on docs, to check if you miss something. https://laravel.com/docs/8.x/fortifyIn case, if you want to narrow this down, I am not sure if you have included
App\Providers\FortifyServiceProvider::class,
this on yourconfig/app
. So, it is never firingFortifyServiceProvider
, to confirm, you could writedd('hit')
, onFortifyServiceProvider's
boot method.
Please, check and let me know your findings.
Answered By - Saroj Shrestha
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.