Laravel-mongodb: Laravel 5.2 Auth Login Error

Created on 21 Jan 2016  路  19Comments  路  Source: jenssegers/laravel-mongodb

Followed the Auth guidline and the user registration works fine but user login fails with the following error message:

ErrorException in EloquentUserProvider.php line 110:
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in /vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 378 and defined

Most helpful comment

In your app/Model/User.php you can try:

`
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;

class User extends \Eloquent implements Authenticatable
{
use AuthenticableTrait;
`

All 19 comments

+1

Larevel 5.2 changed the auth system. Did you use the Authenticatable trait?

I used "class User extends Moloquent" or otherwise migration would not work.

Note: 'Moloquent' => Jenssegers\Mongodb\Model::class

In your app/Model/User.php you can try:

`
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;

class User extends \Eloquent implements Authenticatable
{
use AuthenticableTrait;
`

In case someone else has the same issue as me, @gieroj 's solution worked.

My error:
ErrorException in Builder.php line 216:
Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must be an instance of Illuminate\Database\Query\Grammars\Grammar, null given, called in /your path/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1876 and defined

User model becomes the following:

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;

class User extends Eloquent  implements Authenticatable
{
    use AuthenticableTrait;

@gieroj 's solution worked for me too. Thanks so much!

I tried the @gieroj 's solution. I have the error :
FatalErrorException in User.php line 9: Class 'Jenssegers\Mongodb\Eloquent\Model' not found
`

namespace App;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;

class User extends Eloquent implements Authenticatable
{
use AuthenticableTrait;

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

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

}`

Do you see what's wrong ?

Thanks

I update everything with composer update and it worked !

@gieroj the solution worked for me too.
Thanks so much!
By the way, how did you fixed this problem before? I think this need troubleshoot.

Feedback from gieroj worked for me as well...many thanks!!!!

i am getting this when i am trying to Auth::login($user); i want to sign in user after registration auto.

"Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in E:\xampp\htdocs\clazzylaravel\vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php on line 294 and defined"

please help me. i checked out many forums no thing work for me.

@gieroj 's fix worked for me - thank you

i have used "composer dump-autoload"
and it works for me.....

@gieroj Thanks. You solved it. :)

@gieroj solution worked for me too. Thanks so much!

@naveenroy001
"composer dump-autoload" also worked for me too. I also stuck into this problem for 5 days. Whenever I install new package, this error occurs.
I tried all the possible solutions on google. but finally I came to know that when-ever we install a new package, Laravel remove all the compiled services. and we ran into this problem. That's why we need to run "composer dump-autoload".

@bajrang8955 solution worked for me. Thanks.

Hello,
@naveenroy001
"composer dump-autoload" also worked for me too, but we want token in API response.

class User extends Eloquent implements Authenticatable
{
use AuthenticableTrait;

wow finally, that's work for me
i'm using
"php": "^7.1.3",
"jenssegers/mongodb": "^3.4",
"laravel/framework": "5.7.*",

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phuocduy1988 picture phuocduy1988  路  3Comments

imrannazirbhat picture imrannazirbhat  路  3Comments

sebastiaanluca picture sebastiaanluca  路  3Comments

yupangestu picture yupangestu  路  3Comments

HassanIbrahim picture HassanIbrahim  路  3Comments