dimanche 21 juin 2020

Laravel- token is not created on register request

I'm newbie in laravel and I'm working on a project including JWT. I've changed the user table that was generated by Laravel: instead of 'name' column , I replaced to 'first_name' and 'last_name' columns.

like that:

    Schema::create('users', function (Blueprint $table) 
    {

            $table->id();
            $table->string('first_name');
            $table->string('last_name');
            $table->string('username');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
    }

I followed the instructions to add the JWT and created AuthController as said. my Register function looks like that:

public function register(Request $request)
    {
     $user = User::create([
            'first_name' => $request->first_name,
            'last_name' => $request->last_name,
            'username' => $request->username,
            'email' => $request->email,
            'password' => bcrypt($request->password)
        ]);

        $token = auth()->login($user);
     
        return $this->respondWithToken($token);
       
    }

after checking on Postman, the user was created and added to the table, but without token. so the request returns empty token. like that:

{

"access_token": null,
"token_type": "bearer",
"expires_in": 3600

};

Why is that?

maybe it's because I've changed the origin columns at the users table? And what should I do to fix it?

thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire