Repository navigation
Description
Is your feature request related to a problem? Please describe.
This feature is related to closed issue #2562, that request was to support signing in a user with the Auth class when a successful Auth.confirmSignUp request was made. The ticket was closed based on a UI implementation that does not solve the issue for users of the Auth class directly.
Describe the solution you'd like
The Auth library should have the option to automatically sign-in a user when they successfully complete the Auth.confirmSignUp request. This should be made possible without requiring the calling application to persist the user's credentials (username and password) between requests.
The following would be my ideal use case:
- A new site user is successfully registered with
Auth.signUp. The site/app does NOT persist the user's password so it is no longer known by the local client. - The site presents the code delivery details (e.g. SMS, Email...) to the new user so they know where to find their confirmation code.
- The site presents a form with a field for the username/email (pre-populated if the user has not left the flow) and an empty field for the confirmation code.
- The user retrieves the confirmation code from the indicated delivery method.
- The user enters the valid confirmation code (and username if not pre-populated) and submits the form.
- The site successfully performs
Auth.confirmSignUpwith the supplied username and code. - The Auth library validates the username and code and upon receiving a valid response is able to generate a fully realized/signed-in CognitoUser locally. No further calls to
Auth.signInare required.
This flow is essentially using the confirmation code as a one-time password which seems reasonable.
Describe alternatives you've considered
Multiple alternatives are discussed in #2562 and the React UI implementation is one alternative although it appears to require persisting the user's password locally between requests which seems like a potential security risk.
Additional context
My assumption based on reading #2562 was that this would require some changes to the Cognito service. I imagine that is the case so that confirmSignUp returns a valid token but I can't find any tickets that represent that change request nor do I even know where to look for such a request.
Activity
jordanranz commentedon Jul 14, 2020
Hey @mousedownmike,
To clarify on the closing of the other issue, this is now implemented in all framework UI implementations of Authenticator and not just React.
Alternatively, if you would like this functionality using only the Auth category, you would just call
Auth.signInon a successfulAuth.confirmSignUp. That being said, maybe the functionality could be baked into theAuth.confirmSignUp, is that what you are asking for?mousedownmike commentedon Jul 14, 2020
Thank you for the response @jordanranz. I've updated the original post to remove mention of other UI frameworks and focus just on the use of the
Authclass.The request is to have the ability to get a signed-in user from
Auth.confirmSignUpwithout providing the user's password. It appears that the React solution (and I presume the Angular solution) relies on having the user's password stored in the app so that it can be used to callAuth.signInonce a successful response fromAuth.confirmSignUpis received.Auth.signIn.I'm proposing that
confirmSignUpreturn a promise withCognitoUser(possibly based onConfirmSignUpOptions) giving something along the lines of:Under the covers, I would presume that if the confirmation were successful and a valid
CognitoUserwere returned,Auth.currentAuthenticatedUserwould reflect that user.Looking at the Cognito API documentation for
ConfirmSignUp, it doesn't appear the Cognito APIs provide a trivial way to implement this so I'm guessing that this needs some support from the Cognito team.Let me know if I can provide more information, I think it would improve the user and developer experience and possibly help keep things more secure. Thanks again!
ianmartorell commentedon Aug 6, 2020
I'm using email verification with a link, which I believe is the most common way of user confirmation on the Internet, and the approach you suggested won't work for those cases unless the password is stored in local storage, which definitely isn't a good idea. Ideally,
confirmSignUpshould sign the user in automatically, it feels like a no brainer to me.nickolanick commentedon Aug 16, 2020
One approach might be the following - on the signUp page user enters the credentials and the confirmation link is sent to our email. Meanwhile, the user is going through the confirmation process, we can try to sign in once every second on the signUp page because we have the credentials in our client memory. The first few requests will fail, with an error of non-confirmation, but after our client clicks the confirmation URL, the user will be automatically signed in, because our request will no longer fail.
The part with checking every few seconds did the user confirm the email is a bit tricky, but in this case, we don't need to save our password in any local storage.
ianmartorell commentedon Aug 17, 2020
I guess that approach would work in some cases, but it requires you to implement checking whether the user is now signed in repeatedly on the confirmation page. If you're simply redirecting after confirmation, then it's a race condition with the sign in requests. And what if the user closes the sign up browser tab? Or if they're on mobile, will the background tab still be able to send the requests?
It gets a lot trickier when the simpler and surefire way is to sign the user in automatically after confirming their account. If their action allowed them to confirm their account, we know for sure they're who they claim to be, so there's no reason to not sign them in.
jefelewis commentedon Aug 27, 2020
I'm having the exact same dilemma. Has there been any resolution to this? These are the issues I'm having/possible scenarios, but I feel like there should be an easier way.
Overview:
After the user receives a Verification Code, the user enters the Verification Code, and the
Account StatusbecomesCONFIRMED. Now that the sign up process is completed, I want to automatically sign in the user in after. It seems inefficient and redundant to redirect the user to the Sign In page to have user enter their information and sign in.Possible Solutions:
confirmSignUpAndSignInmethod that does whatconfirmSignUpdoes, but signs in the user after. Use the email and password from the sign up process and then dispatch the signIn action to sign in the user, but that creates a security risk as mentioned above + edge case if the user doesn't confirmSignUp right away.confirmSignUpevent to keep track of the user confirms the sign up process.Possible Amplify Enhancements:
confirmSignUpand signIn, which would be something along the lines ofconfirmSignUpAndSignIn(If a method exists). I have looked through the AWS Docs and through the issues Amplify-js Github Repo, but have only found that others have had a similar dilemma with no apparent resolution. @mousedownmike would that be a possible solution to add a newconfirmSignUpAndSignInmethod?Additional context
I'm using the AWS Amplify Hub (Auth listener) and the only events that are emitted are the following from the docs:
ianmartorell commentedon Aug 27, 2020
I'm using verification by link and as it currently stands I see no possible way to reliably (and securely) sign users in after confirming their account. This would have to be integrated into the
confirmSignUpmethod. 😕mousedownmike commentedon Aug 27, 2020
Until this gets resolved, my low tech solution is to redirect the user to the sign-in page with their email address pre-populated and the following message:
Onboarding users is something I want to make as frictionless as possible and this is the best approach I've come up with in light of the
confirmSignUplimitations. It's not great, but it's something the user experiences only once so it isn't the end of the world.45 remaining items
abdallahshaban557 commentedon Aug 17, 2022
Hi @oemer-sellwerk - can you please submit a new Github issue for us to track this ask?
ataibarkai commentedon Aug 17, 2022
To confirm I understand --
Auto-signin after signup is now possible even when using 2FA with a text message code?
I.e. the user won't have to enter 2 confirmation codes on initial signup/signin?
All you need is to set
signUpVerificationMethodtocode?If so -- fantastic news!
When is this coming to iOS?
abdallahshaban557 commentedon Aug 25, 2022
@ataibarkai - unfortunately, the user would still need to enter two confirmation codes. One for user confirmation, and the other for 2FA. This is a limitation that has been communicated to the Cognito team.
bmovement commentedon Aug 25, 2022
Wow, that’s quite a limitation. Good to know, thanks.
Squashed commit of the following:
Merge main into in-app-messaging/main (#10264)
wangf1978 commentedon Aug 30, 2022
@abdallahshaban557 This autoSignIn does not introduce clientMetadata/ValidationData in signUp to PreAuthentication_Authentication and PostAuthentication_Authentication trigger, is it possible to keep the client metadata of context?

littlefeatheradmin commentedon Dec 7, 2022
Is there any progress on this issue? Is there any recommended workaround?
UX vice we're either forced to remove MFA (which would be unacceptable security vice) OR skip autoSignIn. The current flow is both confusing to most users and it looks unprofessional :(
MikeSchlosser16 commentedon Aug 16, 2023
I totally agree with this - still no updates?
ponyshchen commentedon Dec 17, 2024
Is there any workaround or bug to track this issue?
jjarvisp commentedon Apr 18, 2025
Hi all, I wanted to provide an update that as of
v6.10.0Amplify JS now supports the CognitoUSER_AUTHflow. This auth flow enables a number of new features and also allows for anautoSignIn()experience where the user doesn't receive back-to-back MFA challenges.The documentation here has an example of how to sign-up with passwordless with auto sign-in enabled.