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

135
Views
How to check multiple conditions using Vue Router global navigation guard

In a vue 3 application which is using pinia, I want to achieve the following

  1. redirect a user to the sign in page whenever a user is not authenticated
  2. redirect a user to a verification page if the user authenticated but not verified
  3. redirect a user to dashboard if the user is authenticated & verified

At the moment I have been able to redirect unauthenticated users to the sign in page and redirect them to the dashboard when authenticated by writing my router index.js file like this

import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: "/signin",
            name: "signin",
            component: () => import("../views/SignIn.vue"),
        },
        {
            path: "/verify",
            name: "verify",
            component: () => import("../views/Verification.vue"),
            meta: { needsAuth: true }
        },
        {
            path: "/dashboard",
            name: "dashboard",
            component: () => import("../views/UserDashboard.vue"),
            meta: { needsAuth: true }
        }
    ]
})

router.beforeEach(async (to, from, next) => {
    if (to.meta.needsAuth && localStorage.getItem('accessToken') == null) next('signin')
    else next()
})

export default router

and here is the method that handles signin

const loginUser = async () => {
  try {
    const res = await axios.post(
      "https://some-api-url/login",
      signin.value,
      {
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
        },
      }
    );

    localStorage.setItem("accessToken", res.data.data.accessToken);

    // redirect home
    router.push("/dashboard");
  } catch (error) {
    error = error.response.data.message;
    alert(error);
  }
};

Now my challenge is the signin endpoint I am calling only return an access token but the dashboard endpoint return the verified status. How can I achieve redirect unverified users to the verification page?

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!