Answer the question
In order to leave comments, you need to log in
Why is NuxtAuth not logging in?
Hello.
Question for those who understand auth.nuxtjs.org
In general:
I am writing a site that should be available only to authorized users.
As an api I use a fake one - https://github.com/techiediaries/fake-api-jwt-json...
I'm trying to understand why, after entering the correct data, the page simply refreshes and does not redirect to the main one. And if you go to the main page manually, it redirects back to the login form ..
After clicking on the "login" button in the fake api terminal, I see that everything is OK and the token is displayed:
login endpoint called; request body:
{ email: '[email protected]', password: 'demo' }
Access Token:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImRlbW9AZGVtby5ydSIsInBhc3N3b3JkIjoiZGVtbyIsImlhdCI6MTYyNDgxNDc3NiwiZXhwIjoxNjI0ODE4Mzc2fQ.uQEVQD1X6BVuGCH2JUtHOOjeYBHBxBtq2uo9OuHSu6Y
POST /auth/login 200 0.709 ms - 207
axios: {
baseURL: 'http://localhost:8000/',
credentials: true
},
auth: {
strategies: {
local: {
endpoints: {
login: {
url: '/auth/login',
method: 'post',
propertyName: 'data.token' },
user: {
url: '/',
method: 'get',
propertyName: 'data' },
logout: false
}
}
}
},
router: {
middleware: ['auth']
},
export const getters = {
isAuthenticated(state) {
return state.auth.loggedIn
},
loggedInUser(state) {
return state.auth.user
}
}
export default {
layout: 'auth',
components: {
Notification,
},
data() {
return {
email: '',
password: '',
error: null
}
},
methods: {
async login() {
try {
await this.$auth.loginWith('local', {
data: {
email: this.email,
password: this.password
}
})
this.$router.push('/')
} catch (e) {
this.error = e.response.data.message
}
}
},
auth: 'guest'
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question