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

AlexMunoz's avatar

Send custom data through Socialite

Hello all.

I'm using Socialite in my project, my current issue is that I have two user types and I need to set the profile type on the Provider callback.

I've seen posts suggesting using session variables but for some reason this approach is not working for me. I'm getting a different session during the Provider callback. I'm not sure what I'm doing wrong.

This is what I'm trying to do right now.

public function redirectToSocialiteProvider(Request $request, $provider)
{

    $request->session()->put('profile_type', $request->input('profile_type'));


    return Socialite::driver($provider)->redirect();
}

And on the callback.

public function handleSocialiteProviderCallback(Request $request, $provider)
 {
    dd($request->session()->all());
 }

The above code just returns the _tokenwhich is different than the initial _token set before the redirect. This code is in the LoginController.

Is there any other way that I can pass custom data to the Provider callback?

Thanks!

0 likes
5 replies
fylzero's avatar

@alexmunoz Session is the right answer, try using the session global helper... it's a bit cleaner.

# Store Value
session(['profile_type' => $request->input('profile_type')]);

# Retrieve Value
session('profile_type');

dd your $request->input('profile_type') to make sure that is a thing before storing it.

Also, what session driver are you using? I'd recommend to just use cookie

Lastly, update your config/session.php file to use 'same_site' => 'lax',

24 likes
AlexMunoz's avatar

@fylzero

Thanks for your response.

I'm now using the global session helper and I also changed the session config as suggested.

I'm still getting the same result. The session is changing after the redirect, so on my callback I have a new session with no data.

I just simplified everything to test, now I have this code:

public function redirectToSocialiteProvider(Request $request, $provider)
    {
        session(['profile_type' => 'test']);

        return Socialite::driver($provider)->redirect();
    }

    public function handleSocialiteProviderCallback(Request $request, $provider)
    {
        dd(session('profile_type'));
    }

I'm still getting a new session on callback.

fylzero's avatar

@alexmunoz Sorry to double-check but did you change 'same_site' => 'lax' in your config/session.php file?

Also, are you getting a value when you dd( $request->input('profile_type') )?

24 likes
AlexMunoz's avatar

Yes, I did change the config and ran config:clear.

And yes, I just changed it to a hard-coded value to test.

I'm certain the issue is that it's a completely different session before and during the callback, I have checked the sessions Ids.

fylzero's avatar

@alexmunoz If that's the case I'd just drop a cookie to the user and be done with it.

# Store Cookie
cookie('profile_type', $request->input('profile_type'), 1);

# Retrieve Cookie
Cookie::get('profile_type');

This will expire the cookie after 1 minute, but you should also unset it when the callback succeeds.

Cookie::forget('profile_type')

Don't forget to put use Illuminate\Support\Facades\Cookie; when using the Cookie facade.

24 likes

Please or to participate in this conversation.