I am trying to create a Social Login with Laravel 5.2.
I am getting user-email, so I need to log-in with only that email.
So, what I have done is-
Auth::attempt(
[
'email' => $user->email
]);
But I am getting this error-
ErrorException in EloquentUserProvider.php line 112:
Undefined index: password
More detail-
I have solved it like this-
//Get the user
$user = User::where('email', '=', $user->email)->first();
//Now log in the user if exists
if ($user != null)
{
Auth::loginUsingId($user->id);
}
And it is working now :).
I appreciate that you've already answered your own question, but here's my response anyway.
It's worth noting that a password is required for a reason. By default, Laravel expects there to be a password, otherwise it's just insecure.
Rather than writing your way around the default auth implementation, why not use the Laravel package Socialite, a package made and maintained by Laravel (read: Taylor). It's quite literally part of Laravel, otherwise you're just reinventing the wheel.
https://github.com/laravel/socialite
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