s how to store jwt in http cookie laravel

Solutions on MaxInterview for s how to store jwt in http cookie laravel by the best coders in the world

showing results for - "s how to store jwt in http cookie laravel"
Gilbert
25 May 2018
1...
2try
3{
4    $user = User::where('email','=',$credentials['email'])->first();
5
6    if ( !($user && Hash::check($credentials['password'], $user->password) ))
7    {
8        return response()->json(['error' => 'invalid_credentials'], 401);
9    }
10
11    $customClaims = ['sub' => $user->id, 'role'=> $user->role, 'csrf-token' => str_random(32) ];
12    $payload = JWTFactory::make($customClaims);
13    $token = JWTAuth::encode($payload);
14} catch(...) {...}
15return response()->json($payload->toArray())->withCookie('token', $token, config('jwt.ttl'), "/", null, false, true); 
16