jwt-auth icon indicating copy to clipboard operation
jwt-auth copied to clipboard

Method [loginUsingId] does not exist.

Open gswy opened this issue 3 years ago • 6 comments

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 avatar Aug 26 '22 07:08 gswy

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

gswy avatar Aug 26 '22 07:08 gswy

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.

Messhias avatar Aug 26 '22 08:08 Messhias

I have customized the user verification process

Please provide more details:

  • your auth and jwt config
  • a complete stacktrace

thanks!

mfn avatar Aug 28 '22 10:08 mfn

You can use tokenById method.

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

andresuntoro avatar Dec 12 '22 08:12 andresuntoro

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.

mfn avatar Feb 21 '24 14:02 mfn

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

andresuntoro avatar Jun 10 '24 11:06 andresuntoro