有没有人在使用官方指南中的 nuxt-auth 时遇到过这个错误?你是怎么解决的?我被困在这里好几天了
错误是defu__WEBPACK_IMPORTED_MODULE_3__ is not a function
我之前在 Vuejs 工作过,并决定研究一下 NuxtJs。在我以前的应用程序中,我的服务器发送了一个客户端无法读取的 HttpOnly cookie。因此,对于身份验证,我尝试了 NuxtAuth,它有一些策略,我注意到不可能使用 HttpOnly cookie 作为策略。我认为这是SSR的局限性。但是有没有办法在 NuxtJs 中使用 HttpOnly Cookies?我的解决方案是仅在我拥有 cookie 的客户端上运行 API 请求。这似乎有效,但我认为这可能不是理想的解决方案。
那么,我如何在 nuxt.config 中为 dev 和 prod env 设置 axios?当我使用 baseURL 属性时,我总是得到 cors,所以我尝试了有效的代理,但 cookie 被拒绝并显示以下消息:cookie“access_token_cookie”由于域权限无效而被拒绝。我认为这是因为代理是 dev 中的本地主机,对吗?有解决办法吗?
那么我有什么想法可以在 Nuxt 中实现 HttpOnly 身份验证吗?
我正在构建一个带有用户登录和注册信息的应用程序。我使用 nuxt/auth 模块来处理身份验证。每当用户登录时,状态都会更改为 true ,不会出现问题。我遇到的唯一问题是,当我调用 set user 方法时,用户信息注册成功,但是每当我刷新浏览器时,即使首先设置成功,我也会丢失用户数据。
我的 nuxt auth 模块的 nuxt.js 配置
auth: {
strategies: {
local: {
token: {
property: "token",
global: true,
},
redirect: {
"login": "/account/login",
"logout": "/",
"home": "/page/ajouter-produit",
"callback": false
},
endpoints: {
login: { url: "http://localhost:5000/login", method: "post" },
logout: false, // we don't have an endpoint for our logout in our API and we just remove the token from localstorage
user:false
}
}
}
},
Run Code Online (Sandbox Code Playgroud)
我的注册/登录组件
async typeForm(e) {
this.typesubmit = …Run Code Online (Sandbox Code Playgroud) 我尝试使用 Nuxt Auth 模块设置谷歌身份验证,但我从谷歌收到以下错误:
Error 400 : invalid_request
Parameter not allowed for this message type: nonce
Run Code Online (Sandbox Code Playgroud)
这是我的配置
Error 400 : invalid_request
Parameter not allowed for this message type: nonce
Run Code Online (Sandbox Code Playgroud)
以及我如何在我的组件中调用 google auth:
// nuxt.config.js
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
auth: {
router: {
middleware: ["auth"],
},
redirect: {
login: "/login",
logout: "/",
callback: false,
home: "/",
},
strategies: {
google: { clientId: "MyClientID", codeChallengeMethod: "" }
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试从这里运行官方演示:https : //github.com/nuxt-community/auth-module/tree/dev/demo 但我遇到了同样的错误。
我正在尝试使用 Sanctum 获取令牌身份验证,nuxt/auth但其中几个功能似乎不起作用。
我有一个端点,通过用户名/电子邮件和密码对用户进行身份验证,API 方面没有问题,它返回具有正确范围的个人访问令牌。
然而,在nuxt/auth这些方法中,setUserToken和setUser都应该能够处理以不同方式授予的用户登录,但这两种方法都没有完成它应该做的事情。
this.$auth.loginWith('sanctum', {
data: this.form
}).then((response) => {
// this should set the token to storage
// then fetch the user with the token
// but it only sets the token to storage
this.$auth.setUserToken(response.data)
.then(() => {
// so I have to fetch the user myself with VuexORM
this.user.api().get('/me')
.then((result) => {
// my user is set to the model, but not to auth
this.$auth.setUser(result.response.data) // sets …Run Code Online (Sandbox Code Playgroud) 当 API 之一使用 Nuxt-Auth 响应未经授权的 401 时如何注销用户?我使用 AXIOS 和 Nuxt-Auth 的内置函数来请求
我的 nuxt-auth 的 nuxt-config 设置:
auth: {
redirect: {
login: '/login',
logout: '/',
callback: '/login',
home: '/panel/dashboard'
},
strategies: {
local: {
token: {
property: 'token',
global: true,
type: 'Bearer',
required: true,
},
user: {
property: 'user',
autoFetch: true
},
endpoints: {
login: {url: '/api/auth/login_verify', method: 'post'},
logout: {url: '/api/auth/logout', method: 'get'},
user: {url: '/api/auth/validate', method: 'get'},
},
},
}
},Run Code Online (Sandbox Code Playgroud)