Reputation: 5111
I would like to send the Bearer token and save it as cookie in frontend.
I pass cookie like this:
return response()->json([
'remember_token' => $user->remember_token,
], 200)->withCookie(cookie('auth_token', 'random_token', 3600));
But it is not setting the cookie at all! Please help!
Upvotes: 4
Views: 1500
Reputation: 14559
Try this:
$cookie = Cookie::make('auth_token', $user->remember_token, 3600);
$response = Response::json('remember_token' => $user->remember_token, 200);
$response->headers->setCookie($cookie);
return $response;
Taken from this answer.
Upvotes: 1