Skip to content
Advertisement

User not loged in after redirect from login with laravel socialite

Hello I am using Laravel Socialite for Oauth authentication with my remote Laravel Paspport app. After getting successfully the user autheticated with passport when I want to get the user to the aplication it redirects me back to login and acts as he is loged out. The client (Socialite is on this git https://gitlab.fit.cvut.cz/ouredma3/trackage ) I tried switching domain in settings but nothing worked. It worked fine before I implemented the Oauth. I ma using Socialite with https://socialiteproviders.netlify.app/providers/laravel-passport.html I hope its all that u need but if anything lemme know and I shall add more info Laravel 7.x, PHP 7.2

This is My loginController.

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

    /**
     * Obtain the user information from Passport
     *
     * @return IlluminateHttpResponse
     */
    public function handleProviderCallback(Request $request)
    {
        try {
            $userSocial  = Socialite::driver('laravelpassport')->stateless()->user();
        } catch (Exception $e) {
             return redirect('/login')->withError($e->getMessage());
        }


        $users  =   User::where(['email' => $userSocial->getEmail()])->first();

        if($users){
            Auth::login($users,true);

        }else{
            $user = User::create([
                'email'         => $userSocial->getEmail(),
                'provider_id'   => $userSocial->getId()
            ]);
            Auth::login($user,true);

        }
        //session(['current_user' => $userSocial]);
        return redirect('/');

    }

Advertisement

Answer

Ok I tried to deploy my application to server and surprise surprise it worked.. The problem is probably with local sessions.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement