Giter VIP home page Giter VIP logo

Comments (14)

sechosebio avatar sechosebio commented on May 9, 2024 4

Hi, I have the same problem, I googled a lot, but I didn't find anything useful

ReflectionException in Container.php line 776:
Class App\User does not exist

In file config.php of this library, I have the same namespace than auth.php

laravel auth.php:

'model' => 'Backend\User',

jwt config.php:

'user' => 'Backend\User',

The piece of code that is returning this error is like the example in the docs

class UserController extends Controller
{

    public function login()
    {
        $credentials = Input::only('email', 'password');
        if (!$token = JWTAuth::attempt($credentials)) {
            return Response::json(['error' => 'invalid_credentials'], 401);
        }
        return Response::json(compact('token'));
    }

Am I missing something in the configuration of JWT?
Thanks

from jwt-auth.

davidwadge avatar davidwadge commented on May 9, 2024 3

I'm having the same issue and changing the namespace in auth and jwt config makes no difference.

from jwt-auth.

ganeshghalame avatar ganeshghalame commented on May 9, 2024 2

I also have the same problem, i.e I have created a separate namespace for models as App\Models\User and even though I have changed model name in jwt config.php as below :

'user' => 'App\Models\User'

I am getting below error:

local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class '\App\User' not found' in /var/www/html/dsa/backend/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:1 26

and doesn't work until I update

laravel auth.php:

'model' => App\Models\User::class

+1 @olso

from jwt-auth.

tymondesigns avatar tymondesigns commented on May 9, 2024

What code are you running to trigger the exception?

from jwt-auth.

tymondesigns avatar tymondesigns commented on May 9, 2024

ok, thanks for the extra info. I will try to reproduce this later today

from jwt-auth.

tymondesigns avatar tymondesigns commented on May 9, 2024

struggling to reproduce this tbh... there's only one place that this is referenced. And it seems likely that this would have been raised by others if it was an issue with the package

Is this still an issue for you ?

from jwt-auth.

olso avatar olso commented on May 9, 2024

It's totally fixable... You have to change the model in Laravel (4.2) auth.php to Namespace\User
Then it will work

from jwt-auth.

MPJHorner avatar MPJHorner commented on May 9, 2024

Did you get to the end of this? Im getting the same error on Lara 5

from jwt-auth.

MPJHorner avatar MPJHorner commented on May 9, 2024

.ignore - I just needed to amend config/jwt.php line 67 amended the User path. Sorted.

from jwt-auth.

GingJan avatar GingJan commented on May 9, 2024

why have to update laravel auth.php 'model' => App\Models\User,doesn't laravel use JWT to authenticate?

from jwt-auth.

sanchitpuri13 avatar sanchitpuri13 commented on May 9, 2024

Hi, I have recently started learning Laravel-5 and i am developing rest web service. To make api secure i am using JWT. I am facing the same issue as stated above.
I have moved the user class from "App\User" to "App\Models\User" and i have added following code in jwt.php

'user' => 'App\Models\User', // code in jwt.php

Inside my Controller Action i have written following code

public function signIn(SignInRequestValidationRules $request)
{
$credentials = $request->only('email', 'password');
try {
if(! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500);
}
return response()->json(compact('token'));
}

Now whenever i am accessing signIn action using postman i am getting the following exception message.
"Class '\App\User' not found At Line 130 in E:\xampp\htdocs\laravel-rest-service\vendor\laravel\framework\src\Illuminate\Auth\EloquentUserProvider.php"

Kindly provide your valuable inputs.

from jwt-auth.

ganeshghalame avatar ganeshghalame commented on May 9, 2024

@sanchitpuri13

It looks cache/autoload issue:
composer dump-autoload
php artisan clear-compiled
and then restart your server. Just search the "App\User" in your project to get better idea

from jwt-auth.

sanchitpuri13 avatar sanchitpuri13 commented on May 9, 2024

@ganeshghalame thanks for giving your valuable time.

I tried the same but the issue still remains, but at end i found the solution. I am providing the link of solution, which can be used by others as well.

mongodb/laravel-mongodb#702.

Rest the changes needs to be done in Auth.php to replace App\User to App\Models\User and same in Jwt.php. I have also replaces all the Occurence of App\User to App\Models\User Project wide as there is no class App\User in my project anymore.

from jwt-auth.

connor11528 avatar connor11528 commented on May 9, 2024

For anyone that is here looking for solution, I ran into this because I had my class as a string. In config/jwt.php change:

'user' => '\App\Models\User'

to

/*
    |--------------------------------------------------------------------------
    | User Model namespace
    |--------------------------------------------------------------------------
    |
    | Specify the full namespace to your User model.
    | e.g. 'Acme\Entities\User'
    |
    */

    'user' => \App\Models\User::class,

from jwt-auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.