2

I'm trying to use VueFire's useCurrentUser() function in a Nuxt 3 application without SSR.

I have configured vuefire in nuxt.config.ts as indicated in the documentation.

export default defineNuxtConfig({
  modules: ['nuxt-vuefire',],

  vuefire: {
    config: {
      apiKey: '...',
      authDomain: '...',
      projectId: '...',
      appId: '...',
    },
  },
})

Then in app.vue I use the code as in the documentation:

<script setup>
const router = useRouter()
const route = useRoute()
const user = useCurrentUser()

onMounted(() => {
  watch(user, (user, prevUser) => {
    if (prevUser && !user) {
      // user logged out
      router.push('/login')
    } else if (user && typeof route.query.redirect === 'string') {
      // user logged in
      router.push(route.query.redirect)
    }
  })
})
</script>

Unfortunately, it always gives me the error:

**

[VueFire] useCurrentUser() called before the VueFireAuth module was added to the VueFire plugin. This will fail in production.

**

Thank you in advance for your help

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Pascal Pivaty
  • 97
  • 1
  • 10

1 Answers1

1

You're missing auth: true in your configuration, e.g.:

  vuefire: {
    auth: true,
    config: ...
Alex
  • 923
  • 9
  • 21