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

elo's avatar
Level 3

Session store not set on request when authenticating via Socialite

I am building API endpoint with Laravel 5.8 using Passport and Socialite for authentication. API authentication with Passport works fine but I am getting a runtime exception error

Session store not set on request

when I try to authenticate using facebook. Here's how I have set up my code

API endpoints

Route::get('login/facebook', 'AuthController@facebookRedirect');

Route::get('login/facebook/callback', 'AuthController@facebookCallback');

Controller methods

public function facebookRedirect()
{
    return Socialite::driver('facebook')->redirect();
}

public function facebookCallback()
{
    return Socialite::driver('facebook')->stateless()->user();
}

Added the facebook key to service.php file like this

'facebook' => [
    'client_id'     =>  env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect'      => env('FACEBOOK_CALLBACK_URL'),
],

How do I resolve this error?

0 likes
6 replies
bobbybouwmann's avatar
Level 88

You need to make sure the socialite routes have a session. This basically means wrapping them in the web middleware group. That group enables sessions through a middleware.

Passport is a stateless API, but socialite itself is not. It needs sessions to function ;)

7 likes
Hugoboss82's avatar

@bobbybouwmann Dude, you saved my life...I just changed my routes to web.php instead of api.php and it worked (using laravel 8) !!

1 like
elo's avatar
Level 3

That's very informative, never knew that. I no longer get that error but now when I try to calling it like this http://localhost:8000/api/v1/login/facebook I get sent to the default laravel login page instead of going to facebook. Keep in mind that I am trying to use socialite for api authentication.

elo's avatar
Level 3

Thanks for sharing the tutorial.

bananabread's avatar

You can also avoid wrapping the routes in the web middleware by using:

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

and

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

Please or to participate in this conversation.