vue.js - Nuxt Auth 两个本地端点
问题描述
我想制作两个本地端点,如下所示:
strategies: {
localOne: {
endpoints: {
login: { url: "token/", method: "post", propertyName: "access" },
user: { url: "user/me/", method: "get", propertyName: false },
logout: false,
}
},
localTwo: {
endpoints: {
login: { url: "user/token/", method: "post", propertyName: "access" },
user: { url: "user/me/", method: "get", propertyName: false },
logout: false,
}
}
},
但我在控制台中遇到以下问题
client.js?06a0:77 TypeError: Cannot read property 'mounted' of undefined
at Auth.mounted (auth.js?facc:112)
at Auth.setStrategy (auth.js?facc:108)
at Auth.loginWith (auth.js?facc:123)
at _callee3$ (log-in.vue?f35c:175)
at tryCatch (runtime.js?96cf:45)
at Generator.invoke [as _invoke] (runtime.js?96cf:271)
at Generator.prototype.<computed> [as next] (runtime.js?96cf:97)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _next (asyncToGenerator.js?1da1:25)
at eval (asyncToGenerator.js?1da1:32)
如何在 nuxt js 中为两个不同的身份验证创建两个端点?先感谢您
解决方案
我想出了不同的决定来让它发挥作用。终于成功了,
this.$axios.post('user/token/', {
id : res.data.id,
firstname: res.data.firstname,
lastname : res.data.lastname,
email: res.data.email
})
.then((resp) => {
this.$auth.setToken('local', 'Bearer ' + resp.data.access)
this.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
this.$auth.ctx.app.$axios.setHeader('Authorization', 'Bearer ' + resp.data.access)
})
.then(() => {
this.$axios.get('user/me/')
.then((resp) => {
this.$auth.setUser(resp.data);
this.$router.push('/')
})
.catch(() => {
console.log(err)
})
让我用简单的话解释一下。我没有使用 nuxt auth local,而是使用它的方法来达到与本地身份验证登录相同的结果。首先,我将数据发布到服务器以创建用户,然后使用其数据登录。简单明了。如果有人需要,我可以更深入地解释它。
推荐阅读
- android - 列表视图始终显示为空,并选择了项目 Android
- node.js - Mendix 设置问题 - 建议的代码不起作用
- reactjs - ReactJs、Redux、Firebase 项目的一般问题
- python - 交换 2 个数据框中的常用值
- python - Pygame,实现按钮的最佳方式?
- smartcard - Java Cards 突然停止响应
- python - Python pandas 标头规范与日期格式
- r - 使用 plot() 时添加 sd 和线连接点
- javafx - 可以直接在 Scene Builder 中编写代码吗?
- android - 是否有一个通用的 try catch for firebase on flutter 涵盖 iOS 和 android 并显示进度条