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

murtaza1904's avatar

How to pass data to socialite login

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

0 likes
3 replies
EngMohammed40's avatar

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

1 like
murtaza1904's avatar
murtaza1904
OP
Best Answer
Level 2

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.

2 likes

Please or to participate in this conversation.