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

168
Vistas
python fido2 server with if statement

I'm using the this example as inspiration for my project about Yubikey. At the end of authenticate.html, I want to add an if-statement. So if the authentication is successfull redirect to a specific page, and otherwise recirect back to the homepage. I've tried different places for the if-statement:

.then(function(response) {
  var stat = response.ok ? 'successful' : 'unsuccessful';
  alert('Authentication ' + stat + ' More details in server log...');
}, function(reason) {
  alert(reason);
}).then(
  function() {
    if(stat=='successful'){
      window.location.replace('https://google.com')
    }
    else {
      window.location = '/';
    }
});
}

and

.then(function(response) {
  var stat = response.ok ? 'successful' : 'unsuccessful';
  alert('Authentication ' + stat + ' More details in server log...');
  if(stat=='successful'){
      window.location.replace('https://google.com')
    }
    else {
      window.location = '/';
    }
}, function(reason) {
  alert(reason);
}).then(
  function() {
});
}

I've never seen Javascript before, but it seemed that I couldn't get around Yubikey and Python (I'm familiar with python) not using JS. None of the above has worked the intented ways.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Asuming you're using fetch then the correct (and simplest) way of handling this would be something like the following:

fetch('some-super-secret-endpoint')
.then(response => {
    if(response.ok)
        window.location = 'https://google.com'
    else 
        window.location = '/'
}).catch(e => {
    console.error(e)
})
about 4 years ago · Santiago Gelvez Denunciar
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