Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!