我們要解決的問題
我正在使用@nuxtjs/auth'Nuxt.js 的模塊進行登錄身份驗證,但是當我使用該loginWith方法時,我收到一個錯誤,因為它跳轉到一個未指定的 URL,而不是 config 中設定的 URL。我需要知道這是如何以及為什么會發生的。
配置中設定的 URL
'/api/v1/auth/sign_in'
發送的實際 URL
/api/auth/login
代碼
配置
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: 'http:localhost:3000'
},
auth: {
redirect: {
login: '/user/login',
logout: '/user/login',
callback: false,
home: '/'
},
strategines: {
local: {
endpoints: {
login: { url: '/api/v1/auth/sign_in', method: 'post', propertyName: 'token' },
logout: { url: '/api/v1/auth/sign_out', method: 'delete' },
user: { url: '/api/v1/auth/user', method: 'get' }
}
}
}
},
組件
import logoImg from '~/assets/images/login_logo.png'
export default {
data () {
return {
logoImg,
userInfo: {
email: '',
password: ''
}
}
},
methods: {
async login () {
await this.$auth.loginWith('local', {
data: {
email: this.userInfo.email,
password: this.userInfo.password
}
})
.then(
(response) => {
localStorage.setItem('access-token', response.headers['access-token'])
localStorage.setItem('client', response.headers.client)
localStorage.setItem('uid', response.headers.uid)
localStorage.setItem('token-type', response.headers['token-type'])
return response
},
(error) => {
return error
}
)
}
}
}
錯誤
OST http://localhost:3000/api/auth/login 404 (Not Found)
uj5u.com熱心網友回復:
您的配置中有拼寫錯誤。
strategines->strategies
http:localhost:3000->http://localhost:3000
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/457857.html
