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

jcorrego's avatar

Laravel Socialite Session errors in 5.2

Im having problems with Laravel Socialite in a fresh 5.2 installation. It appears that session is not retrieved correctly when doing redirect.

0 likes
7 replies
JeroenVanOort's avatar

Could you please explain what you have done and how you came to your conclusion?

I'd guess you did have a succesful authentication with the provider, logged in the user, redirected to the page saying 'yay, you just logged in' and then found the user not to be logged in. If my assumption is true, it could be helpful to log a user in without Socialite and see it that works. If it does, we can look close at Socialite, if dit doesn't, at least we know that this isn't Socialite specific.

acasar's avatar
acasar
Best Answer
Level 13

@jorrego in routes.php, did you define your routes inside the web middleware group? This seems to be a common problem with 5.2 upgrades :)

4 likes
jcorrego's avatar

Actually i have a working instance of socialite in 5.1 and its working perfectly... Right now, i was trying a new installation of laravel 5.2, after fresh install, and using the make:auth artisan command, and adding laravel-socialite, provider and alias, services configuration, created two sample routes, and added two sample methods for facebook, i get the following error when accesing the route:

FatalThrowableError in AbstractProvider.php line 134:
Fatal error: Call to a member function set() on null

This is thrown when doing: return Socialite::driver('facebook')->redirect();

Notes:

  • I m using the facebook app id and keys from my working installation so i dont think that is the problem...
  • I first tested normal user registration and login and it works perfect.
5 likes
jcorrego's avatar

Thanks @anzze. Putting the routes inside web middleware group solved that!!! I see that group includes startSession middleware so i think almost every route should be going in there...

30lines's avatar

I performed the same fix for my problem since it was the same situation, but now I'm getting just a blank white page after visiting the URI for github redirect ( using L5.2, btw ):

Here is my method ( AuthController.php )

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

I put it under the 'web' middleware route group, I have the correct client and secret ID in my .env file, and I included and configured the package configuration information inside of app/services.php

    'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect' => env('GITHUB_REDIRECT')
    ]

Any thoughts?

mn8809's avatar

My problem was that I was issuing a stateless token, however I was forgetting to specify ->stateless() when accessing the return data.

Working callback function

Socialite::driver('google')->stateless()->user();

Please or to participate in this conversation.