Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda