Home > Blockchain >  Question Password reset token in Laravel Breeze Inertia React
Question Password reset token in Laravel Breeze Inertia React

Time:12-28

I have a problem to use password reset view which demanding an token to create the view in laravel breeze combine with inertiajs and reactjs.

my question is : Q1. Where is the token generated? or where do i retrieve the token?

//route
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
            ->name('password.reset');
//controller
public function create(Request $request)
{
    return Inertia::render('Auth/ResetPassword', [
        'email' => $request->email,
        'token' => $request->route('token'),
    ]);
}

as you can see this route demanding a token to create the view but i dont know how to generate the token. and i cant see any page access this route so there is no example about this.

Q2. How do i pass the token to controller

<Link method="get" href={route('password.reset')} data={{ token: token }} as="button">
        Reset
</Link>

im planing to do like code above which i can click from user data grid based on user id so only admin can reset your password. or any better idea to implement this?.

thankyou in advance

CodePudding user response:

If you installed breeze/laravel fresh installation you can simply generate the token using:

$token = $request->user()->createToken($request->token_name);

return ['token' => $token->plainTextToken];

What you need to make sure of is that you are using the trait HasApiTokens in the User Model:

use Laravel\Sanctum\HasApiTokens;
 
class User extends Authenticatable
{
    use HasApiTokens;
}
  • Related