不确定这是否会有所帮助,并且只回答了几个问题(很久以前的其他帐户)。
更新..我读了我的答案然后是问题标题(我认为我的答案确实涵盖了你的一些上下文),但关于标题你也可以使用 auth 来查看plugin。然后,您可以在页面被点击之前处理那里的东西。
我不确定您的代码是如何实现的,但这可能会有所帮助(希望如此)。
如果你没有使用Vuex,我强烈推荐它。 Nuxt Vuex Store Guide
// index/store.js
// At least have the store initialized, but its most likely going to be used..
// page.vue
<template>
...
<div v-else-if="!$auth.loggedIn">
{{ test }}
</div>
...
...
data() {
if (!this.$auth.loggedIn) {
const test = 'Only this will load, no flash'
return { test }
}
}
$auth.loggedIn 是内置的,我在文档中的某个地方读过它
这将解决无闪存问题,您还可以利用加载器屏幕和 asyncData 在渲染视图之前检查state,以避免闪存并在它挂起时填充数据。
您也可以尝试使用 Vuex Actions,我目前正在使用这两个在我现在的过程中。了解nuxtServerInit()
// store/index.js
import axios from 'axios'
export const actions = {
nuxtServerInit ({commit}, {request}) {
// This is good if you have the user in your request or other server side stuff
if (request.user) commit('SET_USER', request.user)
},
async GET_USER({ commit }, username) {
const user = await axios.get(`/user/${username}`)
if (user) commit('SET_USER', user)
}
}
export const mutations = {
SET_USER(state, user) {
// simple set for now
state.auth.user = user || null
}
}
第二个是使用页面本身的fetch()方法组合的。
// page.vue
async fetch({ $auth, store }) {
await store.dispatch('GET_USER', $auth.$state.user)
}
现在您可以根据需要在代码中调用$auth.user。
$auth.user 是我读到的另一个内置 ..somewhere..
您还可以使用$auth.loggedIn 调用$auth.user,以检查user 是否存在于登录$auth.user && $auth.loggedIn 之上。
可能是this.$auth.<value>,具体取决于您尝试引用它的位置。
我知道asyncData()首先被调用并登录我的服务器,然后data()也在服务器控制台中记录值(false,null),但在我的勇敢控制台中它们是@987654344 @,我想要一个答案,哈哈
我一直在努力让 Auth0 以我想要的方式使用 JWTs,但随着我不断爬取,我发现了一些有用的部分(即使在旧的演示中,例如你提到过,lock 的东西什么都没有……)。同样就express 和我的API 而言...无论如何,希望这对(某人)有所帮助。