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
L5 - Call to a member function toUser() on boolean #35
Comments
Hi drawmyattention, You could check for token parsing success before fetching the user, ie: if (! $auth = JWTAuth::parseToken();) {
throw Exception('JWTAuth unable to parse token from request');
}
$user = $auth->toUser(); |
You were right, it wasn't able to parse the token from a POST parameter. I had to set the token in a header (my mistake). However, now when I send a request with an Authorisation bearer {token} header, the parseToken() method no longer kicks out an error, but the toUser() method results in
I'm generating the token using:
Then copying the token generated:
to use in the auth header. I've added a bit of debugging to my code to try to quickly see what's going on, and it looks like the validateStructure() method is called twice. The first time, a token is present but the second time an empty token is being passed, which is causing the Exception to be thrown. |
Thanks, I will have a look into this. Note: I think I will change it so that parse token will throw an exception instead of returning false if the token cannot be extracted from the request. |
Hi! Any news on this? However, when I set it from Laravel using Laravel cookie helper, it gives me 'Wrong number of segments' This is what fails currently
I can verify the token is being generated correctly and the JS app is returning the cookie generated by laravel. As you can see, I set the http only flag as false too. Tried without that as well. Any ideas? |
@shah-newaz I'm not sure if this is related to your issue, but I had a problem with the fact that laravel encrypts cookies. I have made a middleware that checks the token, and this middleware is (apparently) called before the
It was necessary instead to write:
Again, this might not be 100% relevant for your issue, but perhaps some else experienced the same as me :) |
Hi @k4kuz0 !
Like so. Cheers! |
@shah-newaz Glad you found a solution! However note that if you use the solution I mentioned, you can keep the token encrypted, perhaps unnecessary, but extra security is always nice! |
@k4kuz0 Hmm, I think you're decrypting the token by Thanks again! |
I've created a barebones controller that has the demo code in to fetch a user from a token, but i'm getting an error 'Call to a member function toUser() on boolean' when I try to run the toUser() method.
My code to replicate:
The text was updated successfully, but these errors were encountered: