I'm building a custom authentication using Laravel Fortify as a based in my app. I have 2 roles, Admin and User role that are generated by Spatie laravel-permission and they have different login, forgot password, reset password, etc pages.
I have successfully made 2 different password reset links. So for Admin, the password reset links is something like:
http://127.0.0.1:8000/admin/reset-password/{token}
And for User it's gonna be like:
http://127.0.0.1:8000/reset-password/{token}
The problem is that, after the password has been successfully reset, Laravel Fortify will redirect me to 127.0.0.1:8000/login regardless if it's Admin or User.
What I want is to redirect to 127.0.0.1:8000/admin/login if it's reset from http://127.0.0.1:8000/admin/reset-password/{token} and redirect to 127.0.0.1:8000/login if it's reset from http://127.0.0.1:8000/reset-password/{token}
After reading the docs (the Handling The Password Reset Response section), I assume it's handled by PasswordResetResponse, so then I tried to create a custom PasswordResetResponse in app\Providers\FortifyServiceProvider like this:
$this->app->instance(PasswordResetResponse::class, new class implements PasswordResetResponse {
public function toResponse($request)
{
if (Route::current()->getPrefix() === '/admin') {
return redirect('/admin/login');
}
return redirect('/login');
}
});
But it doesn't work. Can someone please help me pointing out what I did wrong?
Just in case this is important, I will include my custom LoginResponse (I also already tried to modify this, but the change doesn't affect my problem):
$this->app->instance(LoginResponse::class, new class implements LoginResponse {
public function toResponse($request)
{
if (Route::current()->getPrefix() === '/admin') {
return redirect('/admin/dashboard');
}
return redirect('/');
}
});