Laravel Socialite GitHub Authentication: Redirect Issue after Successful Authentication

I’m encountering an issue with GitHub authentication in my Laravel app using Laravel Socialite. Despite setting up everything correctly and being able to retrieve user data from GitHub, users aren’t redirected to the dashboard after logging in. I’ve checked my configuration files, but I can’t figure out what’s wrong.

I made sure my GitHub authentication was set up properly in Laravel Socialite, and I expected users to be redirected to the dashboard after logging in. However, despite successful authentication, users aren’t redirected as expected. Instead, they remain on the login page

OAuthController.php:

    public function redirect($github)
    {
        return Socialite::driver($github)
            ->setScopes(['read:user', 'public_repo'])
            ->redirect();
    }

    public function callback($github)
    {
        try {
            $socialUser = Socialite::driver($github)->user();

            $user = User::where([
                'github' => $github,
                'github_id' => $socialUser->id,
            ])->first();

            if (! $user) {
                $user = User::create([
                    'github_id' => $socialUser->id,
                ], [
                    'username' => $socialUser->getNickname(),
                    'name' => $socialUser->getName(),
                    'email' => $socialUser->getEmail(),
                    'github' => $socialUser->github,
                    'github_token' => $socialUser->token,
                ]);
            }

            Auth::attempt($user);

            return redirect()->intended(route('dashboard'));
        } catch (Exception $e) {
            return redirect()->route('login')->with('error', 'Something went wrong with ' . $github . ' login');
        }
    }

This resulted in Socialite actually fetching the data, but not doing anything with it. The config for this is correct, otherwise it would return a redirect_uri error, but this was not the case. Routing is fine too, socialite wouldn’t have been able to fetch otherwise. Which leads me to believe it has something to do with the Query Builder.

But despite my efforts, I’m unsure of what steps to take next. Any advice or suggestions on how to proceed would be greatly appreciated.