JWT token authentication for Rainlab.User

I’m in process of learning the JWT functionality with Rainlab.User plugin
So far everything is ok with account creation and login. I get the token and next I’m trying to get the user data from an endpoint.
The request goes like this:

axios.get('/api/account/user', {
    headers: {
        Authorization: 'Bearer ' + token
    }
}).then(response => {
    console.log(response.data);
});

Next, I’ve set the layout as specified in the documentation:

description = "Auth API Layout"
is_priority = 1

[session]
checkToken = 1

[account]
==
{% if session %}
    {% page %}
{% else %}
    {% do response({error: 'Access Denied'}, 403) %}
{% endif %}

and the user endpoint:

url = "/account/user"
layout = "auth"
title = "user"

[account]
==
{% do response({
    token: session.token,
    session: session.user,
    account: account.user,
    user: user
}) %}

But on that endpoint I’m not getting any data.
session.user is null, account.user is null and so on.
I don’t understand what am I doing wrong here.

Hey @Alex

It looks like this was caused by a small bug in the persistence-checking logic. It will be fixed in v3.0.5 of the User plugin.

Related issue: User token authentication not working? · Issue #542 · rainlab/user-plugin · GitHub

1 Like

I confirm that it works after the update!
Thank you very much!