Jwt-auth: Call to undefined method Illuminate\Auth\RequestGuard::once

Created on 24 Jun 2016  路  3Comments  路  Source: tymondesigns/jwt-auth

Fatal error: Call to undefined method Illuminate\Auth\RequestGuard::once() in D:\webprojects\lumen\vendor\tymon\jwt-auth\src\Providers\Auth\Illuminate.php on line 43

{"message":"Call to undefined method Illuminate\Auth\RequestGuard::once()","code":1,"status_code":500,"debug":{"line":43,"file":"D:\webprojects\lumen\vendor\tymon\jwt-auth\src\Providers\Auth\Illuminate.php","class":"Symfony\Component\Debug\Exception\FatalErrorException","trace":["#0 D:\webprojects\lumen\vendor\laravel\lumen-framework\src\Concerns\RegistersExceptionHandlers.php(55): Laravel\Lumen\Application->handleShutdown()","#1 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns{closure}()","#2 {main}"]}}

Most helpful comment

Please link this issue on the wiki, it can save people a lot of time.

All 3 comments

Lumen isn't supported on the v0.5 branch. You can get (undocumented) support on the 1.0 alpha branch.

The general idea is that instead of using JWTAuth to make all your calls, you configure the application's "guard" to be the JWTGuard in this library. Then when you want to do stuff, you use the regular Auth commands like Auth::user(), Auth::guest(), Auth::check() etc.

There are some basic instructions in this post. I _think_ that's mostly accurate. Though note that LaravelServiceProvider should be changed to LumenServiceProvider. Also steps 5-9 are optional depending on how you want your server to behave.

Once 1.0 gets an official release there will be docs for this.

Please link this issue on the wiki, it can save people a lot of time.

@tdhsmith I'm using this package at version 藛1.0@beta and follow similar instructions that you recommended follow.

Here is my bootstrap/app.php

$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);

if(class_exists('Vluzrmos\Tinker\TinkerServiceProvider')) {
    $app->register('Vluzrmos\Tinker\TinkerServiceProvider');
}

Here is my config/app.php

'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
   'guards' => [
        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],

And the last one AuthController@login method.

public function login(Request $request)
{

        $this->validate($request, [
            'email'    => 'required|email|max:255',
            'password' => 'required',
        ]);

        try {
            if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
                return response()->json(['user_not_found'], 404);
            }
        } catch (TokenExpiredException $e) {
            return response()->json(['token_expired'], $e->getStatusCode());
        } catch (TokenInvalidException $e) {
            return response()->json(['token_invalid'], $e->getStatusCode());
        } catch (JWTException $e) {
            return response()->json(['token_absent' => $e->getMessage()], $e->getStatusCode());
        }

        return response()->json(compact('token'));
}

What i'm doing wrong?

Whenever i request a POST to this login method, this throw this error on my face:

captura de tela 2017-09-22 as 23 11 41

Was this page helpful?
0 / 5 - 0 ratings

Related issues

therealmjk picture therealmjk  路  3Comments

phamduong picture phamduong  路  3Comments

lbottoni picture lbottoni  路  3Comments

lloy0076 picture lloy0076  路  3Comments

hfalucas picture hfalucas  路  3Comments