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

User failed to transfer to token #195

Closed
fengerwoo opened this issue Nov 28, 2022 · 6 comments
Closed

User failed to transfer to token #195

fengerwoo opened this issue Nov 28, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@fengerwoo
Copy link

Subject of the issue

User failed to transfer to token

Your environment:

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 9.33.0
Package version 2.0.0
PHP version 8.1.9

Steps to reproduce

 auth()->login($user);

The user failed to transfer to token. The specific error is reported

Lcobucci\JWT\Token\Builder::relatedTo(): Argument #1 ($subject) must be of type string, null given, called in vendor/php-open-source-saver/jwt-auth/src/Providers/JWT/Lcobucci.php on line 212 in vendor/psy/psysh/src/Exception/TypeErrorException.php on line 53.

Operation screenshot

User Model implements are also correct

@fengerwoo fengerwoo added the bug Something isn't working label Nov 28, 2022
@Messhias
Copy link
Collaborator

Question: did that happen outside the thinker environment too (eg. Web)?

@fengerwoo
Copy link
Author

fengerwoo commented Nov 28, 2022

Question: did that happen outside the thinker environment too (eg. Web)?

@Messhias Yes, so does the web

@fengerwoo
Copy link
Author

fengerwoo commented Nov 28, 2022

@Messhias Change the getJWTCustomClaims in the User Model to the following, and the token can be obtained, but I still don't know what the root problem is. When I used tymon/jwt-auth before, getJWTCustomClaims can return an empty array here

public function getJWTCustomClaims(){
        return [ 'sub' => $this->id, ];
}

Modify screenshot

@Messhias
Copy link
Collaborator

@Messhias Change the getJWTCustomClaims in the User Model to the following, and the token can be obtained, but I still don't know what the root problem is. When I used tymon/jwt-auth before, getJWTCustomClaims can return an empty array here

public function getJWTCustomClaims(){
        return [ 'sub' => $this->id, ];
}

Modify screenshot

I did same as you and worked as well, @eschricker did that happens to you too?

@eschricker
Copy link
Contributor

I don't need to pass ['sub' => $this->id] as custom claim.

I can't reproduce this error.

@Messhias
Copy link
Collaborator

I tried to reproduce the error again and didn't happen, what could be happened it's the $subject it wasn't a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants