Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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); 
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #store #jwt #http #cookie #laravel
ADD COMMENT
Topic
Name
8+7 =