I m using JWT with laravel 5.7 and i want to share user role with jwt token can i do it ? `
/**
* Get a JWT via given credentials.
*
* @return \Illuminate\Http\JsonResponse
*/
public function login()
{
$credentials = request(['email', 'password']);
if (! $token = auth()->attempt($credentials)) {
return response()->json(['email' => 'Email or password wrong'], 400);
}
return response()->json([
'token' => $this->respondWithToken($token),
'user' => auth()->user()
]);
}
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 6000000
]);
}`
i want my payload should be like this { "sub": "1234567890", "name": "John Doe", "admin": true }
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire