"@nuxtjs/auth-next": "5.0.0-1608219886.ec0152d",
"nuxt": "^2.14.7",
auth: {
localStorage: false,
strategies: {
local: {
endpoints: {
refresh: {
url: '/refresh-token',
method: 'get',
propertyName: 'jwt',
},
login: { url: 'login', method: 'post', propertyName: 'token' },
user: { url: 'users/profile', method: 'get', propertyName: false },
logout: false,
},
user: {
property: 'user',
autoFetch: true,
},
token: {
property: 'token',
type: 'Bearer',
required: true,
},
},
},
redirect: {
login: '/entrar',
logout: '/entrar',
home: '/templates',
},
},
To redirect to /templates page after login
It stores all cookies auth._token.local, auth._token_expiration.local and auth.strategy, but it's not redirecting to /template (home)
And even more, if i try to enter a page that needs auth, it redirects me to login page
I also tried to store in localstorage, but still doesn't work
Also after login request, it calls users request just after success
iat is 1 hour
Hi @CavalcanteLeo , I tried to reproduce your issue using auth demo, but for me it's working properly. Maybe you can try to make a repro in codesandbox?
But I see that in your config you're using some deprecated options, like propertyName. Also, if you want to use refresh token, you should change to refresh scheme.
auth: {
localStorage: false,
strategies: {
local: {
scheme: 'refresh', // <- set refresh scheme
endpoints: {
refresh: {
url: '/refresh-token',
method: 'post' // <- probably should be post, like login
},
login: { url: 'login', method: 'post' },
user: { url: 'users/profile', method: 'get' },
logout: false,
},
user: {
property: 'user', // <- should be 'user' or false?
autoFetch: true,
},
token: {
property: 'token',
type: 'Bearer',
required: true,
},
refreshToken: {
property: 'jwt' // <- refresh token property
}
},
},
redirect: {
login: '/entrar',
logout: '/entrar',
home: '/templates',
},
},
You can see more about refresh scheme in docs
Also after login request, it calls users request just after success
Yes, this is expected. If you don't want to call user endpoint after login, then disable user.autoFetch and manually set the user using this.$auth.setUser. See docs of autoFetch and setUser
@CavalcanteLeo Maybe it's a typo issue? Just checking your config again and the endpoints.user.propertyName is false while user.property is user.
User data not set properly might cause the loggedIn state to be false, so no redirect.
I tried the the code above, but still not working,
And my refresh token is GET, not a POST, i just have to call the API sending my token that is about to expire in the header, nothing more
@JoaoPedroAS51
You can try debug the check method of the scheme you're using. If check return valid: false, then loggedIn state will be false
After a video call with @JoaoPedroAS51 we figured out the problem was the way I set the user config in nuxt.config
But if the nuxt-auth have thrown me an error, would be much easier to figure out.
My suggestion is to throw erros back to all requests, then we can figure out much faster.
My error was because the property had to be set as false, and when nuxt-auth made the request, it cound't parse and the state loggedIn was always false.
also nuxt-auth should handle when it occurs, i couldn't parse profile API, my states was loggedIn false but all cookies were set
I really appreciate your time and help @JoaoPedroAS51
@CavalcanteLeo Thank you! :)
I'll add "improve error handling" to to-do list
@JoaoPedroAS51 Right now I am having the same problem but if it establishes the session correctly but does not perform the redirection after a successful login or even when I am inside the session and I press the button that makes logout it does not redirect,
In the console I get the following error when I give F5 to redirect through the auth middleware
Could you give me a hint of what is happening? It seems that I will also have some problem with the configuration
Thanks for everything!

nuxt.config.js
auth: {
redirect: {
login: '/login',
logout: '/login',
home: '/',
},
strategies: {
local: {
scheme: 'refresh',
token: {
property: 'tokens.accessToken',
type: 'Bearer'
},
refreshToken: {
property: 'tokens.refreshToken',
data: 'refresh_token'
},
user:{
property: 'user',
autoFetch: true
},
endpoints: {
login: {
url: 'auth/login',
method: 'POST'
},
user: {
url: 'auth/me',
method: 'GET',
},
logout: {
url: 'auth/logout',
method: 'POST'
},
refresh: {
url: 'auth/refresh',
method: 'POST'
}
},
}
}
}
Most helpful comment
@CavalcanteLeo Thank you! :)
I'll add "improve error handling" to to-do list