Solution skill
Custom Auth Flow With Bad Answer Infinite Loop
Complete solution
Shows how to fix custom Auth Flow With Bad Answer Infinite Loop. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
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
- 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.
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.
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 2 · 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>