Viewed   127 times

I am trying to use login with facebook in laravel 5 using Socialize.

Here is my route file code.

Route::get('fb', function ($facebook = "facebook")
    $provider = Socialize::with($facebook);      
    if (Input::has('code'))
        $user = $provider->user();
        return var_dump($user);
    } else {
        return $provider->scopes(['public_profile','user_friends'])->redirect();

login is success and I get the code but time of get $provider->user() I get the error.

InvalidStateException in AbstractProvider.php line 161



I got temporary solution for that.

public function user()
    //if ($this->hasInvalidState()) {
    //    throw new InvalidStateException;

    $user = $this->mapUserToObject($this->getUserByToken(
        $token = $this->getAccessToken($this->getCode())
    return $user->setToken($token);

comment the $this->hasInvalidState() if condition in AbstractProvider.php file and it's work fine.

Friday, December 23, 2022

I ran into this issue last night and solve it with the following solution.

More information on my issue, I've got

InvalidStateException in AbstractProvider.php line 182

in the function handleProviderCallback() when it re-direct back from Facebook login. It seems to be the same as your issue.

Furthermore I found my issue occurs when I open my site without www. When I open my site with - no problem. At first I think my issue is random until I've got the clue by Chris Townsend's reply to the question - Thank you very much.

The Solution

  1. Go to your www root, check the laravel file config/session.php
  2. Check session Session Cookie Domain The default configuration is 'domain' => null, I made a change to 'domain' => ''.
  3. After 'php artisan cache:clear' and 'composer dump-autoload', I can login with no issue from both and

Be sure to delete your cookies from browser when testing it after these modifications are done. Old cookies can still produce problems.

Thursday, October 27, 2022

Open your .env file under root project. Edit following Lines in it :

MAIL_PORT=587 #Update from 465 to 587

Restart local webserver & It worked.

Saturday, October 22, 2022

You error may be coming from your session manipulation. When you do


The user is already set in the session. You don't need to do your Session::put() thingy. To get the user, do

$user = Auth::user();

To logout, you do

Auth::logout(); //will clear the user from the session automatically

So to summarise, remove all the session manipulations you have in your code. Only play with Auth;

Session::flush(); //DELETE THIS LINE

Add Auth to the top of your controller with

use Auth; //easier to work like that. 
Thursday, December 15, 2022

Yes, you can use addSelect()

From the Query Builder documentation under "Selects":

If you already have a query builder instance and you wish to add a column to its existing select clause, you may use the addSelect method:

$query = DB::table('users')->select('name');
$users = $query->addSelect('age')->get();

Additionally, the API documentation (as apposed to the written documentation) can also shed additional light on what functions are available on core classes.

Tuesday, September 20, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :