nuxt-firebase-auth-starter
nuxt-firebase-auth-starter copied to clipboard
Nuxt 3 RC Support
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
Oh. Will take a look in a bit! Thank you
``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.
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?
Thanks! I can replicate it too by updating to Nuxt RC. Still investigating the problem.
Let's follow this issue https://github.com/nuxt/nuxt.js/issues/13812
Can you guys please confirm if forcing nuxi upgrade works for you?
npx nuxi upgrade --force
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
I'll try to make a module out of this. So we can have auto-import firebase composables, auto-set cookies and stuff
Hey @wobsoriano how is your work on the module progressing? Do you need help?
Ditto that @wobsoriano - I would love a module for this. Happy to contribute.
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.