Hello, Some OAuth providers allow you send optional parameters using "with" method like this:
return Socialite::driver('google') ->with(['hd' => 'example.com']) ->redirect();
Be careful not to pass senstive data
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to pass the role using session but unable to get it after redirect
public function redirectToProvider($provider): RedirectResponse
{
Session::put('role', request('role'));
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback($provider): RedirectResponse
{
Session::get('role');
}
Getting null. I tried the same thing using cookie but getting same issue. Also with method on Socialite isn't useful
Thank you, @engmohammed40 and @sm3rter, for your responses. It turned out to be a rough Friday I realized that the role value was null, which caused the Session to return null during redirection from the provider. I've fixed the issue now.
Please or to participate in this conversation.