question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

challengeName not present after using verifyTotpToken

See original GitHub issue

The problem does not occur when using the aws-amplify-react components but I’m trying to create a custom component for TOTP setup and it doesn’t seem to work correctly.

The following code works without an error

 const verifyTotpToken = async ({ totpCode }) => {
        if (
            !Auth ||
            typeof Auth.verifyTotpToken !== 'function' ||
            typeof Auth.setPreferredMFA !== 'function'
        ) {
            throw new Error(
                'No Auth module found, please ensure @aws-amplify/auth is imported'
            );
        }
        const user = authData;
        console.log('verifyTotpToken, user', user);
        try {
            await Auth.verifyTotpToken(user, totpCode);
            try {
                await Auth.setPreferredMFA(user, 'TOTP');
                setSetupMessage('Setup successfully!');
                logger.debug('set up totp success!');
                triggerTOTPEvent('Setup TOTP', 'SUCCESS', user);
            } catch (err) {
                console.log('setPreferredMFA error', err);
                setError('Setup failed!');
            }
        } catch (err) {
            console.log('setup error', err);
            setError('Setup failed!');
            logger.error(err);
        }
    };

and results in preferredMFA being set to SOFTWARE_TOKEN_MFA

but on signing in there is no challengeName so the user is never asked to enter a code.

If I then try await Auth.setPreferredMFA(authData, 'TOTP') after this I get an error of User has not verified software token mfa

I can’t see why this is not working as it’s not much different to how aws-amplify-react components work.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Oli-Flemmercommented, Jun 25, 2021

SOLUTION I was having the same issue but fixed it by running Auth.currentAuthenticatedUser after Auth.setPreferredMFA finished. Next time the user logs in they should have an auth challenge. The flow goes something like this: setupTOTP -> verifyTotpToken -> setPreferredMFA -> currentAuthenticatedUser -> signOut -> signIn

0reactions
github-actions[bot]commented, Aug 31, 2022

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React & AWS Amplify - User does not have delivery config set ...
challengeName ) { await Auth.verifyTotpToken(userObject, mfaToken); // This would be step 6 in the CLI version above. await Auth.
Read more >
AuthClass | amplify-js
Refer to the documentation for how to setup and use MFA: ... verifyTotpToken(user: CognitoUser | any, challengeAnswer: string): Promise<CognitoUserSession>.
Read more >
Multi-factor authentication - JavaScript - AWS Amplify Docs
With TOTP (Time-based One-time Password), your app user is challenged to complete authentication using a time-based one-time (TOTP) password after their ...
Read more >
Soft-Token Authentication with AWS Amplify, Cognito and ...
A significant gotcha is presented here, note the line: Auth.enableSMS(props.user);. I realised that unless smsMFA is enabled then the workflow ...
Read more >
How to use the aws-amplify.Auth function in aws-amplify - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix ... verifyTotpToken(user, totpCode).then(function () { // set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found