skip to Main Content

It’s my first time trying out this package and I followed the installation guide at https://laravel.com/docs/8.x/passport but when this code block in my controller signup action it throws the error:

$token = $user->createToken('authToken')->accessToken;

Here’s the code for my signup action:

public function signup(Request $request){
    $request->validate([
        'name' => 'required',
        'email' => 'required|string|email:rfc,dns|unique:users',
        'password' => 'required|string|confirmed'
    ]);

    $user = new User([
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password)
    ]);

    $user->save();

    $token = $user->createToken('authToken')->accessToken;

    return response()->json([
        'message' => 'Successfully created user!',
        'access_token' => $token
    ], 201);
}
  • Passport Version: 10.0
  • Laravel Version: 8.16.1
  • PHP Version: 7.4.13
  • Database Driver & Version: MySQL 5.7.24

4

Answers


  1. Chosen as BEST ANSWER

    I found the solution on: https://github.com/laravel/passport/issues/1381.

    In composer.json just add "lcobucci/jwt": "3.3.3" and execute composer update.


  2. I had the same environment and adding "lcobucci/jwt": "3.3.3" package and update composer fixed my issue.

    Login or Signup to reply.
  3. ## Works in Laravel 7
    composer require lcobucci/jwt:"^3.0"
    
    Login or Signup to reply.
  4. i got this issue when i execute the
    composer update
    command.
    after a bit of searching i figure it found and downgraded my composer.lock file again to its old versions by

    git restore composer.lock
    

    then executed the

    composer install
    

    for installing the packges again

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search