import { Component } from '../../lib/vues6/vues6.js' import { auth_api } from '../service/AuthApi.service.js' import { location_service } from '../service/Location.service.js' const template = `
{{ app_name }}
Your account has multi-factor authentication enabled. Please enter the code generated by your authenticator app to continue.
{{ error_message }}
{{ other_message }}
Lost your MFA device?
` export default class MFAChallengePage extends Component { static get selector() { return 'coreid-mfa-challenge-page' } static get props() { return ['app_name'] } static get template() { return template } loading = false verify_code = '' verify_success = false error_message = '' other_message = '' async watch_verify_code(new_verify_code, old_verify_code) { if ( new_verify_code.length === 6 ) { this.loading = true const result = await auth_api.mfa_attempt(new_verify_code) this.verify_success = result && result.is_valid if ( !this.verify_success ) { this.other_message = '' this.error_message = `Uh, oh! It looks like that's not the right code. Please try again.` this.loading = false } else { this.error_message = '' this.other_message = `Success! Redirecting...` await location_service.redirect(result.next_destination, 1500) } } else if ( new_verify_code.length > 6 ) { this.verify_code = old_verify_code } } async on_key_up(event) { if ( event.keyCode === 13 ) { // Enter was pressed - don't submit the form event.preventDefault() event.stopPropagation() return false } } async on_do_recovery(event) { await location_service.redirect('/auth/mfa/recovery', 0) } }