【发布时间】:2020-02-07 00:00:47
【问题描述】:
我使用 Vue JS v2 已经有一段时间了,我对它很满意。最近我开始使用 Nuxt JS,到目前为止我能够掌握大部分内容。但是在网上搜索了无数个小时之后,我仍然无法找到在 Nuxt JS 中创建 Vue 应用程序之前如何使用 firebase onAuthStateChanged() 的方法。
让我解释一下
在 Vue 2 中,我所做的通常是在 main.js 文件中
import Vue from 'vue'
import App from './App.vue'
import { auth } from '@/firebase/init'
let app = null
// ⚡ Wait for firebase auth to init before creating the Vue app
auth.onAuthStateChanged(() => {
// init app if not already created
if (!app) {
app = new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
}
})
但在 Nuxt JS 中,整个 main.js 文件都被封装了。现在我知道我可以使用插件来执行Vue.use() 之类的操作,但这些事情在创建 Vue 应用程序之后再次发生。
我想将 vue 应用程序的创建包含在 firebase 身份验证检查中,所以我看不出有什么方法可以实现这一点。所以,如果有人知道如何实现这一点,请告诉我。
请注意,我不会尝试根据身份验证状态进行任何重定向。我知道这些答案已经存在,并且我已经检查过了。
【问题讨论】:
标签: javascript firebase firebase-authentication nuxt.js