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

danielhe4rt's avatar

My session is not persisting

I'm trying to make some 3rd party authentication on my application but when I get redirected, the session vanish and I don't really know why it is happening.

Here's my code:

public function getAuthenticate(Request $request)
    {
        $code = $request->get('code');
        $service = new DiscordService();

        $auth = $service->validateToken($code);
        $userData = $service->getAuthenticatedUser($auth['access_token']);

        $user = User::where(['email' => $userData['email'] , 'discord_id' => $userData['id']])->first();

        if(!$user) {
            $user = User::create([
                'name' => $userData['username'],
                'email' => $userData['email'],
                'discord_id' => $userData['id'],
            ]);
        }

        Auth::login($user);

       if(Auth::check()) {
            dump('workss');
        }
    }

Here is where i'm trying to check:

After I do the 3rd party authentication:

Back to the home page to check if has any authenticated object there:

Any clue of what is actually happening here?

0 likes
2 replies
aurawindsurfing's avatar

Hey @danielhe4rt

Do you see those 2 lines in your env file?

SESSION_DRIVER=file
SESSION_LIFETIME=120

Or you maybe changed it to something else and it simply does not work regardless of your 3rd party auth process?

Snapey's avatar

check that your browser contains the laravel cookies after authentication.

Look in developer tools and then 'Application' (chrome) you should see a cookie which matches the client to its session on the server. If this is not present then you can never be 'logged in.'

check this so that it can be ruled out

Please or to participate in this conversation.