Closed cliffordh closed 3 years ago
Hey @cliffordh
Please excuse the late response.
In Nuxt "static" mode there is no server. Respectively the "server" is run once during statically pre-rendering the pages. During that time, there is no request from any user and therefore no authentication can be done.
Further, in static mode, the initial page load won't trigger the middleware, because that is simply a pre-rendered html page. There is no javascript (middleware) that is run before the html file is loaded.
The middleware is only triggered before routing to another route.
So your code won't work. Not a Firebase issue but a Nuxt specific (resp. nature of pre-rendering) issue in general, so if you have further questions to this I'd advise you to rather ask this in the Nuxt community (e.g. their Discord server).
Imho you have two options:
1) Switch to SPA mode or deploy the application in server mode.
2) Exclude the routes (see here) that you don't want to be statically pre-rendered. That way, they will be SPA pages that are not pre-rendered, and your middleware code should work fine on these files.
I'd go for solution 2 in your case, since pre-rendering is awesome.
If I access https://mysite.com/admin
The middleware fails to prevent access. However, if I'm running in dev, "npm run dev" then things behave as expected. It's only when I do a "npx nuxt generate", "npm run start" and serve a static site that the middleware fails. I added the "process.client" stuff to the middleware because npx nuxt generate was failing without it.
Any ideas?
Here is the relevant nuxt.config.js for nuxtjs/firebase:
Here is my middleware:
Here is my store: