What was reported:
Issue aws-samples/amazon-cognito-passwordless-auth#208 (closed, 6 comments): Hi guys, I've been fiddling around with this package and I don't know how to handle the error when a bad code is submitted since the auth flow just loops infinitely here's my pseudo example in Angular. ``` import { Component, OnInit, ViewEncapsulation, EventEmitter } from '@angular/core'; import { Passwordless } from "amazon-cognito-passwordless-auth"; import { authenticateWithSRP } from "amazon-cognito-passwordless-auth/srp"; export class LoginComponentComponent implements OnInit { myPromise: Promise[string] constructor() { } ngOnInit() { Passwordless.configure({ userPoolId: environment.

What works:
In a custom auth flow, the function you pass to customChallengeAnswer is invoked every time a custom answer is needed. If it doesn't return a fresh promise on each invocation, the challenge resolves immediately with the old (wrong) value and the flow loops forever when a bad code is submitted. Fix: make sure customChallengeAnswer returns a new promise every time it's called, so a wrong code produces a proper retry or error instead of looping.