PHP-Open-Source-Saver / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
MIT License
684 stars 106 forks source link

Method [loginUsingId] does not exist. #182

Open gswy opened 1 year ago

gswy commented 1 year ago

Summary

I have customized the user verification process. At this time, I use the user's unique identifier to log in, and it is prompted that there is no such method.

gswy commented 1 year ago
auth('app')->loginUsingId($user->id);
Messhias commented 1 year ago

You can open a new PR to help with that, lately, I'm very busy. Otherwise, I'll take a look at it by myself.

mfn commented 1 year ago

I have customized the user verification process

Please provide more details:

thanks!

andresuntoro commented 1 year ago

You can use tokenById method.

Example: auth('app')->tokenById($user->id);

mfn commented 5 months ago

You can use tokenById method.

This does something else: it generates a new token.

auth('app')->loginUsingId($user->id);

You can't use loginUsingId on a API guard.

loginUsingId is from the StatefulGuard contract, but the whole point of an JWT/API token is that it's stateless.

The \PHPOpenSourceSaver\JWTAuth\JWTGuard is a regular \Illuminate\Contracts\Auth\Guard and hence only provides the methods on the contract.

What you can do is call ->setUser() and provide your own user.

But everything else it not meant to be here.

IMHO this issue can be closed.

andresuntoro commented 1 month ago

This does something else: it generates a new token.

The issue creator says he wants to use the user's unique ID for login which I assume he wants to generate a new token based on that ID. That's why I answered he could use the tokenById method in that case.

In \PHPOpenSourceSaver\JWTAuth\JWTGuard there is already a method (tokenById) derived from \Tymon\JWTAuth\JWTGuard that can be used.

https://jwt-auth.readthedocs.io/en/develop/auth-guard/#tokenbyid

image