Lumen+JWT token + Flutter request: Unauthorized error

  jwt, laravel, lumen, unauthorized

I have flutter app use login with facebook and gmail ,I want after register to return data conatin token.

I have no problem with request which register in database successfully.
but I get error : Unauthorized message after the request done and registered successfully :

   $user = User::create(
       [
        'social_id'=>$request->id,   
        'username'=>$request->username,
        'email'=>$request->email,
        'pics'=>$request->pics,
        'role'=>'user'
       ]);
   if($user){
       $credentials = request(['email', 'password']);

       if (! $token = auth()->attempt($credentials)) {
           return response()->json(['error' => 'Unauthorized'], 401);
       }
       else{
       $data = [
        'social_id'=>$request->id, 
           'username'=>$request->username,
           'email'=>$request->email,
           'status' => 'success',
           'token' => $token
       ];}
   }
return $data;  

Source: Laravel

Leave a Reply