Skip to content

PHP code snippet – s How to store jwt in http cookie laravel?

...
try
{
    $user = User::where('email','=',$credentials['email'])->first();

    if ( !($user && Hash::check($credentials['password'], $user->password) ))
    {
        return response()->json(['error' => 'invalid_credentials'], 401);
    }

    $customClaims = ['sub' => $user->id, 'role'=> $user->role, 'csrf-token' => str_random(32) ];
    $payload = JWTFactory::make($customClaims);
    $token = JWTAuth::encode($payload);
} catch(...) {...}
return response()->json($payload->toArray())->withCookie('token', $token, config('jwt.ttl'), "/", null, false, true); 
See also  How to use asterisk in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.