Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
Is it bad practice to set an "isAuthenticated" flag in LocalStorage?

This is more of general frontend question, but for context, I'm using Vue 3 and vue-router.

I'm constructing functionality for authentication with Vue 3. Because I'm not using Vuex, I couldn't find a way to access state from the file where the router is instantiated. So I thought maybe I'd stick a flag called isAuthenticated into LocalStorage.

When the user logs in, isAuthenticated gets set to true, and then the router reads from this to validate subsequent redirects. This is very different from storing a token in LocalStorage – I store my tokens in httpOnly cookies.

For those that know Vue3/Vue-router, it looks like this:

  Router.beforeEach(async (to, from) => {

    // localStorage.isAuthenticated = false

    const isAuthenticated = localStorage.isAuthenticated;

    if (
      // make sure the user is authenticated
      isAuthenticated !== 'true' &&
      to.meta.requiresAuth &&
      // Avoid an infinite redirect
      to.path !== '/login'
    ) {
      // redirect the user to the login page
      return '/login'
    }
  })

It would be no big deal if someone hacked this and changed the flag to true; my backend will reject any API call that doesn't have the right JWT token.

But is this bad practice? It feels a little flimsy, and I'm looking to write a robust and secure app.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda