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 Static Site Auth #3023
Comments
See nuxt auth module and also this example for best patterns |
Thanks, let me clarify our issue. When you are running a Nuxt static site (so no server is present), middleware does not run on page load. Is there anything we can do about this? |
You need to use the plugins directory. Nuxt will run this code prior to rendering completely on the client. Do what you need for auth and then commit to your store. Here’s my file using firebase and a repo of doing this https://github.com/davidroyer/nuxt-firebase-auth/blob/master/plugins/fireauth.js |
@davidroyer I tried to use plugins to do authCheck, it caused other problem:
|
This seems like a specialized request for assistance, please check out the channels over at Discord for help. Closing as there's been no updates over 90 days. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey all
We're deploying our Nuxt app via Netlify (so as a static site with the
npm run generate
command. There is no server).We're using an auth service that stores a token in
localstorage
when a user is authenticated. We're then accessing that token using a Vuex store. Once the app is loaded we are then able to use Nuxt's middleware to protect certain routes from non-authenticated users etc.But when the page is refreshed obviously the store is empty. So we're trying to re-verify the user on page load by dispatching an action. We've tried to do this via the
fetch
method in a page component and via a plugin, but both seem to fire too late and ourisAuthenticated
getter is returning false even for already-signed-in users.Middleware doesn't seem an option as it's not fired on client refresh and obviously
nuxtServerInit
is out of the question as we, er, don't have a server.What are our best options for page refresh on a static site?
Thanks
The text was updated successfully, but these errors were encountered: