1

I have this function for socialite login:

public function login()
{ 
    return Socialite::driver('facebook')->redirect();
}

public function callback()
{
     return redirect('/')->with('message','Logged in!!');
}

The callback function only redirects to homepage where there is a form to add, a song:

 public function add(Request $request)
    {
          $newSong = new Song();
          $newSong->name=$request->song;
          $newSong->added_by=Socialite::driver('facebook')->user()->name;
          $nrwSong->save();
   }

But when i try to add added_by field in database from this social authentication, it gives

InvalidStateException in AbstractProvider.php

What am i doing wrong here? I can see user details if i dd(Socialite::driver('facebook')->user()); in callback function.

Steve
  • 1,622
  • 5
  • 21
  • 39
  • This [InvalidStateException in AbstractProvider.php](http://stackoverflow.com/questions/29629287/laravel-5-geting-invalidstateexception-in-abstractprovider-php) appears to happen a good bit. There is even a [Laracast](https://laracasts.com/discuss/channels/laravel/socialite-invalidstateexception-in-abstractproviderphp) on it. Were these resources helpful? – WEBjuju Dec 02 '16 at 13:16

1 Answers1

1

You should be getting the users information in the callback (Which is the only place in the documentation you see that call being done). Facebook is sending the user back to that callback with data (inputs). The state part you are running into is part of these inputs and also saved in the session. When you call Socialite::driver('facebook')->user(), it is looking in the current request for the state input, which doesn't exist because you are now on a different request because you redirected the user.

lagbox
  • 48,571
  • 8
  • 72
  • 83
  • So isn't there any other way to access user details from other than callback function? – Steve Dec 03 '16 at 02:42
  • If you want that information later you should persist it some how. That `user` method requires a request that has certain inputs (it is expecting to be called in the callback) as that is where the social provider is sending the user after it authenticates, with data. – lagbox Dec 03 '16 at 02:56