Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adnanerlansyah403's avatar

Forcing user account selection for Laravel Socialite GitHub logins

I recently implemented Laravel Socialite so that users can login using their GitHub accounts. Everything seems to be working but one issue I'm having is that after I login for the first time in a browser I am unable to switch to a different Github account if I log out and then log back in. Once the following code is executed in the LoginController it automatically (all in one action) logs me in with my GitHub account and redirects me back to my site without giving me the option to choose a different Github account.

public function redirectToProvider()
{
    return Socialite::driver('github')->redirect();
}

Is there a way to force the user to explicitly choose which account they wish to login with every time?

Thanks everyone 🙏

0 likes
3 replies
Nakov's avatar

That does not really sounds right, as the Github token returned will be different for the user, so it won't get authenticated on your app automatically if they happened to login with a different user on Github side. If they are logged in already with the same account they authorized your app to use, then showing them to select a github account again will be an unnecessary step.

https://laravel.com/docs/9.x/socialite#routing

So you store the github_token in your users model, and the code you provided will redirect to github so that the user can authorize your app to collect his information the first time, after that as long as the same account is logged in in your browser session it should auto-log them in into your site, but if they logout on github and login in with different account, then that's a new user.

adnanerlansyah403's avatar

@Nakov But how about the Google account. It can be login with another account after user's logout. Using method with(), like this:

public function redirectToProvider()
{
    return Socialite::driver('google')->with(["prompt" => "select_account"])->redirect();
}
1 like
Nakov's avatar

@adnanerlansyah403 but even if you don't add that, I am saying that if the currently "active" user account on the other platform won't login automatically on your side unless the user authorizes it. It is a different token.

Please or to participate in this conversation.