Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method [loginUsingId] does not exist. #182

Open
gswy opened this issue Aug 26, 2022 · 6 comments
Open

Method [loginUsingId] does not exist. #182

gswy opened this issue Aug 26, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@gswy
Copy link

gswy commented Aug 26, 2022

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 gswy added the enhancement New feature or request label Aug 26, 2022
@gswy
Copy link
Author

gswy commented Aug 26, 2022

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

@Messhias
Copy link
Collaborator

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
Copy link
Contributor

mfn commented Aug 28, 2022

I have customized the user verification process

Please provide more details:

  • your auth and jwt config
  • a complete stacktrace

thanks!

@andresuntoro
Copy link

You can use tokenById method.

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

@mfn
Copy link
Contributor

mfn commented Feb 21, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants