I'm implementing an online reservation system using Laravel Framework version 5.6 and Laravel Socialite to implement gmail login.
I have a method that checks if user is logged in before reservation, or it puts reserveData and redirectUrl specified by an uniqid in redis and cookie to fetch it after logging in:
public function checkAuthentication(Request $request)
{
$reserveData = json_decode($request->input('reserveData'), true);
Session::put('reserveData', $reserveData);
if (!Auth::check()) {
$reserveID = uniqid();
Cookie::queue(Cookie::forget('reserveID'));
Cookie::queue(Cookie::make('reserveID', $reserveID, 1440));
$stepData = [
'redirectUrl' => route('reserve', ['productId' => $reserveData['productId']]),
'reserveData' => $reserveData
];
Redis::set($reserveID, serialize($stepData));
return redirect()->route('redirectToGmail');
}
return redirect()->route('reserve', ['productId' => $reserveData['productId']]);
}
redirectToGmail:
public function redirectToGmail()
{
return Socialite::driver('google')->redirect();
}
The problem is, the uniqid doesn't exist in cookie after returning back from gmail only for the first time that user tries to login:
public function login()
{
$user = Socialite::driver('google')->stateless()->user();
dd(Cookie::get());
}
from Cookie is removed after gmail login
No comments:
Post a Comment