Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt 3 RC Support #3

Open
areindl opened this issue Apr 28, 2022 · 11 comments
Open

Nuxt 3 RC Support #3

areindl opened this issue Apr 28, 2022 · 11 comments

Comments

@areindl
Copy link

areindl commented Apr 28, 2022

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

@wobsoriano
Copy link
Owner

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

@areindl
Copy link
Author

areindl commented Apr 29, 2022

``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
Copy link
Author

areindl commented May 2, 2022

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?

@wobsoriano
Copy link
Owner

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

@wobsoriano
Copy link
Owner

wobsoriano commented May 2, 2022

Let's follow this issue nuxt/nuxt#13812

@greendesertsnow
Copy link

greendesertsnow commented May 16, 2022

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

@wobsoriano
Copy link
Owner

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
Copy link
Owner

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

@areindl
Copy link
Author

areindl commented Jul 29, 2022

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

@jontybrook
Copy link

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

@ktiedt
Copy link

ktiedt commented Aug 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants