使用 laravel socialite 从登录重定向后用户未登录

User not loged in after redirect from login with laravel socialite

您好,我正在使用 Laravel Socialite 通过我的远程 Laravel Paspport 应用程序进行 Oauth 身份验证。成功获得用户身份验证后,当我想让用户进入应用程序时,它会将我重定向回登录并在他注销时执行操作。客户端(Socialite 在这个 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 我希望这就是你所需要的,但如果有什么让我知道的,我会添加更多信息 Laravel 7.x, PHP 7.2

这是我的登录控制器。

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

    /**
     * Obtain the user information from Passport
     *
     * @return \Illuminate\Http\Response
     */
    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('/');

    }

好的,我尝试将我的应用程序部署到服务器上,结果令我惊讶。问题可能出在本地会话上。