Giter Club home page Giter Club logo

Comments (7)

tymondesigns avatar tymondesigns commented on May 10, 2024 11

Looks like you need to import the class because you are within a namespace.

Either by prefixing JWTAuth (\JWTAuth) with a backslash where you using it or adding the use statement at the top of your class:

use Tymon\JWTAuth\Facades\JWTAuth;
// or
use JWTAuth;

from jwt-auth.

abdulkader avatar abdulkader commented on May 10, 2024 6

Hi,

Please follow the instruction at https://github.com/tymondesigns/jwt-auth/wiki/Installation

it worked for me after changing config/app.php aliases from

'JWTAuth' => Tymon\JWTAuthFacades\JWTAuth::class,
to
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',

from jwt-auth.

vikramparihar avatar vikramparihar commented on May 10, 2024 4

Change controller line
use JWTAuth;
with
use Tymon\JWTAuth\Facades\JWTAuth;

from jwt-auth.

tymondesigns avatar tymondesigns commented on May 10, 2024 1

or you could always inject the instance via the constructor:

<?php namespace App\Http\Controllers\Api;

use App\Http\Controllers\Api\ApiController;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\JWTAuth;
use Illuminate\Http\Request;

class AuthController extends ApiController {

    protected $auth;

    public function __construct(JWTAuth $auth)
    {
        $this->auth = $auth;
    }

    public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');

        try {
            // attempt to verify the credentials and create a token for the user
            if (! $token = $this->auth->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'));
    }
}

from jwt-auth.

hzburki avatar hzburki commented on May 10, 2024 1

This fix does not work for Lumen 5.5 ... I receive the following error

BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ $app ]] in class Illuminate\Cache\CacheManager

Please advice ...

from jwt-auth.

NickvdMeij avatar NickvdMeij commented on May 10, 2024

That worked, nice!
I'd suggest adding this to the documentation, so other wont encounter the same problem ;-)

from jwt-auth.

raniesantos avatar raniesantos commented on May 10, 2024

@vikramparihar Hi, can you help me understand why use JWTAuth throws an error when I try to use toUser() even though I configured it in the config/app.php aliases.

Also, why does use Tymon\JWTAuth\Facades\JWTAuth work, what's the difference?

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.