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

How to retrieve the User session after login #15

Closed
chrisvidal opened this issue Sep 12, 2018 · 2 comments
Closed

How to retrieve the User session after login #15

chrisvidal opened this issue Sep 12, 2018 · 2 comments

Comments

@chrisvidal
Copy link

Hi,
How to retrieve the User session after login?
I am building API using this plugin to handle the authentication.
How do I get the logged user session?
I tried the usual

$user = Auth::getUser();

but it does not work

thanks

@vdomah
Copy link
Owner

vdomah commented Sep 13, 2018

From your question I see you need just User model instance not user's session. To achieve this you need to get user's id from token and then get the model:

$user_id = JWTAuth::authenticate($token)->id;
// or
$user_id = JWTAuth::parseToken()->authenticate()->id;
// then
$model = UserModel::findOrFail($user_id);

@chrisvidal
Copy link
Author

ok thanks, I came up with

$token = JWTAuth::parseToken()->getToken();
$user = JWTAuth::authenticate( $token );

@vdomah vdomah closed this as completed Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants