https://github.com/nuxt-community/auth-module
Static site behaves the same, regardless of "universal" or "spa" mode
There is a difference in the generated site when using "universal" mode vs "spa" mode.
This issue was originally discovered here. We noticed that the auth module does not work in static mode. The problem was that $auth.state
always returned false, even after a successful login. We later discovered that this only occurs if the static site was generated with mode
set to universal
in nuxt.config.js
. When setting the mode to spa
login worked correctly and $auth.state
correctly returns the login state.
So somewhere there is a difference in the generated code for the static site. I'm not sure if this is intended behavior or a bug. If this is intended, it needs to be made clear in the documentation.
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as 馃晲Pending
will not be automatically marked as stale.
Confirmed in [email protected]
Using nuxt generate
in universal mode is not appreciate for _any dynamic content_ including authentication because server response is prerendered. Auth works fine in the standard universal mode using nuxt start
so it would better idea using a hosting (either VPS or serverless) and running the nuxt server or using SPA mode.
@pi0 Thank you for the explanation. The problem is not that auth is not working, it's that there is just a behavioral difference between static sites generated in spa or universal mode. In my opinion this should at least get documented, because as it is right now there are people (me included) who stumble upon this and are left wondering why these two are different. I would even argue that it is counter-intuitive for the generated output to be different depending on which mode was used.
@dominikmontada Right. Actually, this should be better to documented about static generate. But it is not either limited to auth or a _bug_ from auth module. I would suggest moving this issue to the docs repo. /cc @manniL
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as pending
will not be automatically marked as stale.
-- nevermind
I think there are more differences worth documenting. For example middlewares.
Statically rendered page in
Middlewares only execute on route navigation, NOT on initial page load.
Middlewares execute both, on page load and subsequent navigation
Most helpful comment
I think there are more differences worth documenting. For example middlewares.
Statically rendered page in
Universal Mode:
Middlewares only execute on route navigation, NOT on initial page load.
SPA Mode
Middlewares execute both, on page load and subsequent navigation