tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.29k stars 1.54k forks source link

Call to an undefined static method Illuminate\Support\Facades\Auth::refresh() #2218

Open khrigo opened 1 year ago

khrigo commented 1 year ago

Subject of the issue

I receiving from phpstan Call to an undefined static method Illuminate\Support\Facades\Auth::refresh()

Your environment

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 10.0
Package version 2.0
PHP version 8.1
kingkero commented 11 months ago

The default Auth facade does not support the refresh() method, it is specific to JWTGuard. You can use a workaround like

    $guard = Auth('api');
    if (! $guard instanceof JWTGuard) {
        // handle wrong guard, i.e. throw runtime exception
    }

    return response()->json([
        'token_type' => 'Bearer',
        'access_token' => $guard->refresh(),
    ]);