nuxt-firebase-auth-starter icon indicating copy to clipboard operation
nuxt-firebase-auth-starter copied to clipboard

Nuxt 3 RC Support

Open areindl opened this issue 2 years ago • 11 comments

Hi @wobsoriano

I had your starter running nicely with Nuxt 3 Beta. But today I upgraded to Nuxt 3 RC and it stopped working.

The error message on server side states that Auth is undefined.

Have you tried upgrading yet?

Best Anton

areindl avatar Apr 28 '22 20:04 areindl

Oh. Will take a look in a bit! Thank you

wobsoriano avatar Apr 29 '22 09:04 wobsoriano

``Cool @wobsoriano!

So to give you a bit more context:

This is my auth.server.ts:

import { getAuth } from 'firebase-admin/auth'
import formatUser from '~/helpers/format-user'
import app from '../config/firebase-admin.config'

// Acts like nuxtServerInit.
// Checks if token is valid on first load.

export default defineNuxtPlugin(async () => {
    const token = useCookie('token', {
        path: '/',
    })
    const user = useUser()

    try {
        if (token.value === undefined) return
        const result = await getAuth(app).verifyIdToken(token.value)
        user.value = formatUser(result)
    } catch (e) {
        console.log('AuthError: ' + e)
        // Not authenticated or invalid token
        token.value = null
    }
})

The frontend is not loading then. On the backend console (while running npm run dev) I see:

[nuxt] [request error] Cannot read property 'Auth' of undefined
  at $id_b788ed7e (./.nuxt/dist/server/server.mjs:15176:44)  
  at async __instantiateModule__ (./.nuxt/dist/server/server.mjs:16599:3)

When I take out the code in the plugin, the frontend loads nicely.

areindl avatar Apr 29 '22 11:04 areindl

Hi @wobsoriano,

I created a fork of your repo to make it easier to reproduce:

https://github.com/areindl/nuxt3-firebase-auth-starter

I upgraded to Nuxt 3 and now it shows the exact same error message.

Do you have any idea yet?

areindl avatar May 02 '22 15:05 areindl

Thanks! I can replicate it too by updating to Nuxt RC. Still investigating the problem.

wobsoriano avatar May 02 '22 23:05 wobsoriano

Let's follow this issue https://github.com/nuxt/nuxt.js/issues/13812

wobsoriano avatar May 02 '22 23:05 wobsoriano

Can you guys please confirm if forcing nuxi upgrade works for you? npx nuxi upgrade --force

greendesertsnow avatar May 16 '22 17:05 greendesertsnow

Can you guys please confirm if forcing nuxi upgrade works for you? npx nuxi upgrade --force

npx nuxi upgrade --force didn't help at all. I'm on the latest version.

Only experimental.viteNode = true made it work

wobsoriano avatar May 17 '22 04:05 wobsoriano

I'll try to make a module out of this. So we can have auto-import firebase composables, auto-set cookies and stuff

wobsoriano avatar May 17 '22 04:05 wobsoriano

Hey @wobsoriano how is your work on the module progressing? Do you need help?

areindl avatar Jul 29 '22 14:07 areindl

Ditto that @wobsoriano - I would love a module for this. Happy to contribute.

jontybrook avatar Aug 05 '22 17:08 jontybrook

Similar problems. If I rename the middleware and auth files to not .ts I can get the UI but anytime trying to implement the firebase-admin calls basically falls flat on its face.

ktiedt avatar Aug 22 '22 20:08 ktiedt