Handle case when user selects Cancel in BankId app

This commit is contained in:
Andreas Eriksson 2021-02-27 17:21:09 +01:00
parent 9701d0c4c2
commit bcc36e1de4
2 changed files with 6 additions and 2 deletions

View File

@ -14,7 +14,7 @@ export enum LoginEvent {
export interface LoginStatusChecker {
token: string
on: (event: 'OK' | 'PENDING' | 'ERROR' | 'USER_SIGN', listener: (...args: any[]) => void) => LoginStatusChecker
on: (event: 'OK' | 'PENDING' | 'ERROR' | 'USER_SIGN' | 'CANCELLED', listener: (...args: any[]) => void) => LoginStatusChecker
cancel: () => Promise<void>
}
@ -39,7 +39,7 @@ class Checker extends EventEmitter {
const response = await this.fetcher('login-status', this.url)
const status = await response.text()
this.emit(status)
if (!this.cancelled && status !== 'OK' && status !== 'ERROR!') {
if (!this.cancelled && status !== 'OK' && status !== 'ERROR!' && status !== 'CANCELLED') {
setTimeout(() => this.check(), 1000)
}
}

4
run.js
View File

@ -60,6 +60,10 @@ async function run() {
status.on('USER_SIGN', () => console.log('USER_SIGN'))
status.on('ERROR', () => console.error('ERROR'))
status.on('OK', () => console.log('OK'))
status.on('CANCELLED', () => {
console.log("User cancelled login")
process.exit(0)
})
api.on('login', async () => {
console.log('Logged in')