Laravel loginUsingId() didnt remeber the login state on new page

435 views Asked by At

I am trying to integrate Socialite in my laravel web app.

When I am trying to login with FB ID using loginUsingId() it makes user login and redirect to homepage as expected, but when I visited some other page on the same domain it forgets that the user is login every time and shows the login and signup button. Dont know why its happening here my default login system is working fine.

I am using following code for laravel socialite

public function redirectToProvider()

{

return Socialite::driver('facebook')->stateless()->redirect();

}

public function handleProviderCallback()
{

$user = Socialite::driver('facebook')->stateless()->user();
$userId=$user->getId();

 $buyerUser = buyerData::where('buyerData_fb_id', $userId)->first();

//using my custom guard
  Auth::guard('buyer')->loginUsingId($buyerUser->id,true);

return redirect()->intended('/');
}

Any help? Thanks

1

There are 1 answers

0
Sok Hai On BEST ANSWER

using Auth::login($user) instead;

Auth::guard('buyer')->login($buyerUser, true);