Jwt-auth: Get current authenticated user

Created on 2 Jul 2017  路  4Comments  路  Source: tymondesigns/jwt-auth

I would like to know if there is a method to get the current authenticated user but return false if not.

I tried :

$user = JWTAuth::parseToken()->authenticate()

But this is returning a response :

{ "message": "The token could not be parsed from the request", "status_code": 500 }

I would like to return true if there is the token match an user and false in any case else.

Any help ?

Thank you.

stale

Most helpful comment

How are you sending your token to the server? If, like me, you are putting the token in a cookie, you can't use JWTAuth::parseToken() as it will not find the token.

As mentioned in the docs here you can set the token manually via JWTAuth::setToken('foo.bar.baz');, and subsequently use JWTAuth::authenticate() to get the user instance.

All 4 comments

how are you sending the token in the request ? means like this test.dev?token=dasdsdsadsa

check this this might help you https://youtu.be/jWYqulDpZWo?t=5m40s

How are you sending your token to the server? If, like me, you are putting the token in a cookie, you can't use JWTAuth::parseToken() as it will not find the token.

As mentioned in the docs here you can set the token manually via JWTAuth::setToken('foo.bar.baz');, and subsequently use JWTAuth::authenticate() to get the user instance.

You can try:

if ( \JWTAuth::getToken()) {
     $user = \JWTAuth::parseToken()->toUser();
}

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

therealmjk picture therealmjk  路  3Comments

lloy0076 picture lloy0076  路  3Comments

hfalucas picture hfalucas  路  3Comments

johncloud200 picture johncloud200  路  3Comments

kofi1995 picture kofi1995  路  3Comments