Home

Issue: 3023

Nuxt Static Site Auth

[issue link]

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 our isAuthenticated 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

This question is available on Nuxt.js community (#c2618)