JWT Auth API

JSON Web Token Authentication for your OctoberCMS API integrated with RainLab.User

Back to JWT Auth API Support

darnpunk
darnpunk

How can I get the signed in user data from another plugin? I am able to sign in and when I do a request in a restricted area it works fine. But how can I access the existing user object? I tried using BackendAuth::getUser() but it doesn't work.

I would like to check the user id of the user making request and do some ownership checks on a record. How do I do this?

vdomah
vdomah

First, JWTAuth works with front-end user not backend by default. About how to get user object:

    $user_id = JWTAuth::parseToken()->authenticate()->id;
    $model = UserModel::find($user_id);

Last updated

darnpunk
darnpunk

It works, thanks!

Andy Kay
Andy Kay

Just a quick note for anyone using the very helpful snippet above (Thank you vdomah) - in your API controller, don't put the above in your _construct otherwise if the Token isn't valid (e.g. expired), it won't return the correct {error: token_expired} type response, instead it shows the Laravel/OctoberCMS debug page

1-4 of 4