Closed al-mcnichol closed 1 month ago
btw, "Auth" is my own convention, where I export a custom Auth object to expose the APIs from 'aws-amplify/auth' not to be confused with amplify versions below v6. This was to localize options needed.
export const Auth = {
signIn: (params) => signIn({ ...params, options}),
signInCustomWithoutSRP: (params) => signIn({ ...params, options: { ...options, authFlowType: 'CUSTOM_WITHOUT_SRP'} }),
confirmSignIn,
signUp: (params) => signUp({ ...params, options: { ...options, ...params.options }}),
confirmSignUp: (params) => confirmSignUp({ ...params, options}),
confirmResetPassword: (params) => confirmResetPassword({ ...params, options}),
updateUserAttributes: (params) => updateUserAttributes({ ...params, options}),
resetPassword: (params) => resetPassword({ ...params, options}),
updatePassword,
fetchUserAttributes,
sendUserAttributeVerificationCode,
getCurrentUser,
fetchAuthSession,
resendSignUpCode,
signOut,
decodeJWT,
autoSignIn,
};
Hello, @al-mcnichol 👋. Are you able to provide additional code tied to your auth flow that precedes your confirmSignUp()
code provided above? And can you give more details on where the "The autoSignIn flow has not started, or has been cancelled/completed" error is coming from more specifically via a network request or screenshot?
Any additional code related to your custom Auth setup may be helpful to share as well as possibly a minimal sample repo for easier reproduction. Thanks!
@cwomack - Here is our custom UI, which ultimately calls Amplify signUp API
SignUp API:
await Auth.signUp({
username: 'fake.email@fake.com',
password: 'Fake@Passw0rd',
attributes: {
given_name: 'Fake First',
family_name: 'Fake Last',
},
autoSignIn: {
// enables auto sign in after user is confirmed
enabled: true,
},
})
ConfirmSignUp & autoSignIn APIs:
await Auth.confirmSignUp({ username, confirmationCode: code })
.then( async ({ isSignUpComplete, userId, nextStep}) => {
let isSignedIn;
console.log('confirmSignUp::isSignUpComplete | ', isSignUpComplete);
console.log('confirmSignUp::userId | ', userId);
console.log('confirmSignUp::nextStep | ', nextStep);
// If autoSignIn is enabled then call autoSignIn API only if signUpStep === 'COMPLETE_AUTO_SIGN_IN
if (isSignUpComplete && nextStep.signUpStep === 'COMPLETE_AUTO_SIGN_IN') {
// Auth.autoSignIn() may fail with msg::"The autoSignIn flow has not started, or has been cancelled/completed"
isSignedIn = await Auth.autoSignIn().catch(() => { /*noop*/ });
console.log('confirmSignUp::autoSignIn | ', isSignedIn)
if (isSignedIn){
await setCurrentAuthProvider('cognito');
globalThis.dispatchEvent(new Event('auth.signin'));
emit('auth.signin');
return actionReturnStatus.success(userId);
}
}
// If autoSignIn is enabled but Auth.autoSignIn() failed then, as a fallback, display
// the sign-in screen with success alert to allow the user to manually sign-in. Only show
// signIn screen if signUp was completed successfully, otherwise assume catastrophic error.
if (isSignUpComplete && !isSignedIn) {
storeAPI.set('screen', ScreenConstants.SIGN_IN);
storeAPI.set('alert', {
msg: 'Success! Please sign in.',
type: 'success',
});
return actionReturnStatus.success(userId);
}
return Promise.reject({ name:'CustomException::SignUpFailedMiserably', message: errMsg });
})
@al-mcnichol, thank you for the additional code and context. It looks like the issue here could be tied to the fact that you're wrapping the autoSignIn()
API, which will break the intended behavior at runtime because this API's implementation may change depending on the nextStep
property (which is swamped at runtime). Can you test and see if removing your Auth wrapper object and calling the autoSignIn()
API directly resolves the issue?
Also, is there a reason why you're creating the wrapper for the Auth API's? Not only will it break the intended behavior of the autoSignIn
API, but it eliminates the tree-shaking advantages that Amplify does for you.
@cwomack Thanks so much for pointing that out. I used the API directly and it worked like a charm. The wrapper was to minimize repeat code for additional options needed but obviously not the right way to go.
Before opening, please confirm:
JavaScript Framework
Web Components
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
Calling autoSignIn() after confirmSignUp() when signUpStep is "COMPLETE_AUTO_SIGN_IN" is throwing error "The autoSignIn flow has not started, or has been cancelled/completed".
Expected behavior
I expected this to set local storage with the current signed in user tokens, etc
Reproduction steps
This is being done in a single session where a modal is presented to user to sign-up (autoSignIn: true), email sent with the code, then code validated.
console.log output:
confirmSignUp::isSignUpComplete | true confirmSignUp::userId | undefined confirmSignUp::nextStep | {signUpStep: 'COMPLETE_AUTO_SIGN_IN'}
Code Snippet
Log output
aws-exports.js
No response
Manual configuration