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

71
Visualizações
Vue Navigation Guard Infinite Redirection

I have a navigation guard as follows:

import authConfig from "./auth.config";
 
export function authGuard(to,from, next) {
    const publicPages = [
      '/login', 
      '/register', 
      '/home', 
      '/forgotpassword',
     
    ];
    const authRequired = !publicPages.includes(to.path);
    const loggedIn = localStorage.getItem(authConfig.USER_LOCAL_STORAGE_KEY);   
    let resetPasswordRequired = true
        
    if (authRequired && !loggedIn ) {     
        return next('/login');        
    }       

    if(loggedIn && resetPasswordRequired) {
      return next('/resetpassword')
    }

    else return next();
    
}

It works fine without the if block for resetpassword.

I cannot figure out why infinite redirect error occurs.

Any ideas?

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You currently have a infinite redirect at:

if(loggedIn && resetPasswordRequired) {
  return next('/resetpassword')
}

As resetPasswordRequired is always true due to let resetPasswordRequired = true and while loggedIn changes to true, your code always ends up redirecting to /resetpassword.

An approach could be to store information in local storage during login, if the user really needs to reset his passwort and set this information to false, before you redirecting.

Another approach would be to save the state of resetPasswordRequired in a store and change it´s state before redirecting.

The third approach would be to manage the process of changing the password on your login page and recieve information, if the user needs to reset his password initial, from a database during login.

about 4 years ago · Juan Pablo Isaza Relatório
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