|
446 | 446 | function authenticateWithUsername(event) {
|
447 | 447 | return authenticate(event, document.getElementById('username').value);
|
448 | 448 | }
|
449 |
| -function authenticate(event, username) { |
450 |
| - return performCeremony({ |
451 |
| - getIndexActions, |
452 |
| - getRequest: urls => getAuthenticateRequest(urls, username), |
453 |
| - statusStrings: { |
454 |
| - init: 'Initiating authentication ceremony with server...', |
455 |
| - authenticatorRequest: 'Asking authenticators to perform assertion...', |
456 |
| - success: 'Authentication successful!', |
457 |
| - }, |
458 |
| - executeRequest: executeAuthenticateRequest, |
459 |
| - }).then(data => { |
| 449 | +async function authenticate(event, username) { |
| 450 | + try { |
| 451 | + const data = await performCeremony({ |
| 452 | + getIndexActions, |
| 453 | + getRequest: urls => getAuthenticateRequest(urls, username), |
| 454 | + statusStrings: { |
| 455 | + init: 'Initiating authentication ceremony with server...', |
| 456 | + authenticatorRequest: 'Asking authenticators to perform assertion...', |
| 457 | + success: 'Authentication successful!', |
| 458 | + }, |
| 459 | + executeRequest: executeAuthenticateRequest, |
| 460 | + }); |
| 461 | + |
460 | 462 | if (data.registrations) {
|
461 | 463 | addMessage(`Authenticated as: ${data.registrations[0].username}`);
|
462 | 464 | }
|
463 | 465 | return data;
|
464 |
| - }).catch((err) => { |
| 466 | + |
| 467 | + } catch (err) { |
465 | 468 | setStatus('Authentication failed.');
|
466 | 469 | if (err.name === 'InvalidStateError') {
|
467 | 470 | addMessage(`This authenticator is not registered for the account "${username}". Please try again with a registered authenticator.`)
|
|
472 | 475 | }
|
473 | 476 | console.error('Authentication failed', err);
|
474 | 477 | return rejected(err);
|
475 |
| - }); |
| 478 | + } |
476 | 479 | }
|
477 | 480 |
|
478 | 481 | function deregister() {
|
|
0 commit comments