Immutable solution version
Custom Auth Flow With Bad Answer Infinite Loop
Complete solution
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.
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.
Evidence
In the GitHub issue, the reporter asked: Custom Auth Flow With Bad Answer Infinite Loop. The working answer that came out of the thread: 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. Source: https://github.com/aws-samples/amazon-cognito-passwordless-auth/issues/208
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_sQrYDKQVlLl977ocPwEP2Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Custom Auth Flow With Bad Answer Infinite Loop <span>— Vectle</span></a>