Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moprocto's avatar

Socialite: SessionGuard.php line 439: Argument 1 passed to Illuminate\Auth\SessionGuard::login()

I followed this tutorial line by line https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-facebook-login.html#.WBfgxJMrJxg to integrate FB login into my app. I am using L5.2 and not 5.3. For some reason, I get the error

 ErrorException in SessionGuard.php line 439: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

I have never seen this before and I can't figure out why the user is not being created before login attempt

My user model

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

0 likes
5 replies
katifrantz's avatar

You should rather show us your controller please . It's more helpful .

moprocto's avatar

@maitrefrantz

here is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\SocialAccountService;
use Socialite;
use Auth;
use DB;
use App\User as Users;

class SocialAuthController extends Controller
{
    public function redirect()
    {
        return Socialite::driver('facebook')->redirect();
    }

    public function callback(SocialAccountService $service)
    {
        $user = $service->createOrGetUser(Socialite::driver('facebook')->user());
        print_r($user);
        var_dump($user);
        //auth()->login($user);

        //return redirect()->to('/social/fb');
    }

 
}

I think I narrowed the issue down to

$user = $service->createOrGetUser(Socialite::driver('facebook')->user());

returning Null

the function comes from

<?php

namespace App;

use Laravel\Socialite\Contracts\User as ProviderUser;

class SocialAccountService
{
    public function createOrGetUser(ProviderUser $providerUser)
    {
        $account = SocialAccount::whereProvider('facebook')
            ->whereProviderUserId($providerUser->getId())
            ->first();

        if ($account) {
            return $account->user;
        } else {

            $account = new SocialAccount([
                'provider_user_id' => $providerUser->getId(),
                'provider' => 'facebook'
            ]);

            $user = User::whereEmail($providerUser->getEmail())->first();

            if (!$user) {

                $user = User::create([
                    'email' => $providerUser->getEmail(),
                    'name' => $providerUser->getName(),
                ]);
            }

            $account->user()->associate($user);
            $account->save();

            return $user;

        }

    }
}
moprocto's avatar

Progress:

var_dump($account->user);

returns Null

but $account->user_id returns the real Id of the user as identified in my user table.

However, in my controller, I changed

auth()->login($user);

to

Auth::loginUsingId($user); with hopes that I can at least log the user in by their ID....but no I get a NULL on that too and

Auth::check() returns false

moprocto's avatar

Progress:

This probably not the answer... but I truncated the social_accounts table and deleted the user attached to my Facebook account's email and the system works again. This was extremely bizarre.

clay's avatar

Error says you must implement the interface Authenticatable but instead you extend it.

Please or to participate in this conversation.