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

170
Views
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 answers
Answer question

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 Report
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!