Closed gitsakil09 closed 3 years ago
autoFetchUser
should be added to local
not strategies
this would disable fetching user after a successful login. if you want disable it entirely set user
to false
change propertyName
's value to token
there is no need for data.token
unless the response's data is like {user:{}, data:{token:''}}
to show any errors in user input from backend like incorrect credentials
await _this.$auth
.loginWith('local', {
data: _this.loginInfo
})
.then((response) => {
// check the response.data for any messages before setting the user for example:
if (response.data.messages) {
// show messages
return
}
_this.$auth.setUser(response.data.user) // this data is ok
})
.catch((error) => {
// here I am getting JWT token error and this error comes from /user/info route
})
Im having the same/similar issue
//nuxt.config.js
/*
** Auth module configuration
** See https://auth.nuxtjs.org/#
*/
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'auth/login', method: 'post' },
user: false,
logout: { url: 'auth/logout', method: 'get' }
},
tokenRequired: true,
autoFetchUser: false
// tokenType: false
}
}
If i try and use loginWith('
local'i get
Strategy local is not defined!`
Im ultimately going to use a cookie auth system
Closing here, as this is an old issue and has already been answered by @talal424 :)
Still having this issue in 2023. local: {autoFetchUser: false} doesn't prevent user autofetch. Neither does local: {user: false} or local: {user: {property: false, autoprefetch: false}}. endpoints.user is set to false.
I have followed the instructions but still It is trying to fetch the user after login request. For example when i try to login my system returns me a message, what I want is to display that message but auth is automatically calling the user routes and when the credentials are wrong then it is setting the undefined as token value. My Nuxt configs are here..
BTW I am getting the user info nicely but what I want is to show the message when credentials are wrong and disabling the auto fetch user My Login.vue
Thanks :)