Static GitHub Issues

[3023] Nuxt Static Site Auth

prev: Error: Could not compile template
next: DeprecationWarning: Tapable.plugin

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

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2618">#c2618</a>)</em></sub></div>