Home Forcing user account selection for Laravel Socialite plugin
Post
Cancel

Forcing user account selection for Laravel Socialite plugin

Laravel Socialite

I remember when I implemented Laravel Socialite in one of my website for users to login using their Google+ accounts. Everything was working fine but there was one issue after login for the first time user were unable to switch to a different Google account if they log out and then log back in.

Once the following code is executed in the LoginController.php :

1
2
3
4
public function redirectToProvider()
{
    return Socialite::driver('google')->redirect();
}

It automatically logs them in with Google account and redirects back to site without giving them the option to choose a different Google account.

The problem was same for other social login like Facebook and Linkedin.

The solution was to add a parameter "select_account" like below:

1
2
3
4
public function redirectToProvider()
{
   return Socialite::driver('google')->with(["prompt" => "select_account"])->redirect();
}

This worked for me.

Fairly simple solution but was not mentioned in @laravel documentation anywhere.

I hope it help someone.

This post is licensed under CC BY 4.0 by the author.