Laravel Socialite: InvalidStateException

后端 未结 25 1150
感动是毒
感动是毒 2020-11-27 13:56

I\'m using Laravel Socialite to add a Facebook connect button on a website. Sometimes, I\'ve got this error on callback:

exception \'Laravel\\Socialite\\Two\         


        
25条回答
  •  自闭症患者
    2020-11-27 14:14

    If you still need help you can use my code, it works for me. You just need to create two routes and update the users table. Don't forget to make password nullable, since you won't get one from the facebook users The code in my controller:

    public function redirectToProvider()
    {
        return Socialize::with('facebook')->redirect();
    }
    
    public function handleProviderCallback(User $user)
    {
        $money = Socialize::with('facebook')->user();
    
        if(User::where('email', '=', $money->email)->first()){
        $checkUser = User::where('email', '=', $money->email)->first();
        Auth::login($checkUser);
        return redirect('home');
         } 
    
        $user->facebook_id = $money->getId();
        $user->name = $money->getName();
        $user->email = $money->getEmail();
        $user->avatar = $money->getAvatar();
        $user->save();
    
        Auth::login($user);
        return redirect('home');
    
    }
    

提交回复
热议问题