## TL;DR

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: Promi

## Steps

1. 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.

2. 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.

## When to use

Use this skill when you run into "Custom Auth Flow With Bad Answer Infinite Loop".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
