I have a Facebook login I am performing with OAuth2, and then I am using Laravel 4's built in Authentication system to log the user back in on revisit. For the majority of users, I see no issues with what I have, but for one user, he is seeing the following error appear on login:
ErrorException
Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Auth\UserInterface, null given
open: */nfs/c09/h04/mnt/139243/domains/crowdsets.com/vendor/laravel/framework/src/Illuminate/Auth/Guard.php
* /**
* Log a user into the application.
*
* @param \Illuminate\Auth\UserInterface $user
* @param bool $remember
* @return void
*/
public function login(UserInterface $user, $remember = false)
{
$id = $user->getAuthIdentifier();
Here is the relevant login/authentication code in the controller:
$check = Fan::where('fbid', '=', $user['uid'])->first();
if(is_null($check)) {
$fan = new Fan;
$fan->fbid = $user['uid'];
$fan->email = $user['email'];
$fan->first_name = $user['first_name'];
$fan->last_name = $user['last_name'];
$fan->gender = $user['gender'];
$fan->birthday = $user['birthday'];
$fan->age = $age;
$fan->city = $city;
$fan->state = $state_abbrev;
$fan->image = $user['image'];
$fan->friend_ids_url = $user['friends'];
$fan->friend_ids_unpacked = $friend_ids;
$fan->save();
$new = Fan::where('fbid', '=', $user['uid'])->first();
Auth::login($new);
return Redirect::to('fans/home');
}
else {
Auth::login($check);
$fan = Fan::find(Auth::user()->id);
$fan->image = $user['image'];
$fan->save();
return Redirect::to('fans/home');
var_dump($user);
}
This is my code in the model for the table I am using to keep user information, called "Fans":
<?php
use Illuminate\Auth\UserInterface;
class Fan extends Eloquent implements UserInterface {
protected $guarded = array();
public static $rules = array();
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword()
{
return $this->password;
}
This is very perplexing because this login works for all of the other profiles I have tried. It is only with this friend's profile that it is throwing this error. I will also add, that on login (or retries) it will create multiple entries for this user in the database/table. This authentication system is supposed to be set up to prevent exactly this. Is there anything I'm missing?
in the create() method in the LoginController you must return the $user that worked for me
protected function create(array $data)
{
$user = User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return $user;
}
Try refactor your code to this:
$fan = Fan::where('fbid', '=', $user['uid'])->first();
if (is_null($fan)) {
$fan = new Fan;
$fan->fbid = $user['uid'];
$fan->email = $user['email'];
$fan->first_name = $user['first_name'];
$fan->last_name = $user['last_name'];
$fan->gender = $user['gender'];
$fan->birthday = $user['birthday'];
$fan->age = $age;
$fan->city = $city;
$fan->state = $state_abbrev;
$fan->image = $user['image'];
$fan->friend_ids_url = $user['friends'];
$fan->friend_ids_unpacked = $friend_ids;
$fan->save();
} else {
$fan->image = $user['image'];
$fan->save();
}
Auth::loginUsingId($fan->getAuthIdentifier());
return Redirect::to('fans/home');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With