Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticatorBaseState loses set credentials when app goes to background and then comes back to foreground #88

Closed
sasaar opened this issue Aug 13, 2024 · 4 comments
Labels
pending-maintainer-response Issue is pending response from an Amplify team member question Further information is requested

Comments

@sasaar
Copy link

sasaar commented Aug 13, 2024

Description:

App uses Authenticator with custom UI to signup, signin and reset password. The following bug appears when reseting password: AuthenticatorBaseState seems to lose already set credentials (username) if app goes to background and then comes back to foreground (new instance created?).

Steps to reproduce:

  1. App uses Authenticator with custom UI views to signin, signup and reset password:
var body: some Scene {
    WindowGroup {
        Authenticator(
                signInContent: { signInState in
                    MySignInView(state: signInState)
                },
                signUpContent: { signUpState in
                   MySignUpView(state: signUpState)
                },
                confirmSignUpContent: { confirmSignUpState in
                    MySignUpConfirmationView(state: confirmSignUpState)
                },
                resetPasswordContent: { resetPasswordState in
                    MyResetPwdView(state: resetPasswordState)
                },
                confirmResetPasswordContent: { confirmResetPwdState in
                    MyResetPwdConfirmView(state: confirmResetPwdState)
                }
            ) { _ in
                ContentView()
            }
      }
}
  1. Select reset password. Enter Email and then put app to the background. Open app again, entered username appears still in Email text field, press continue.

  2. Reset password code is sent to your email. Enter confirmation code and new password, and select continue. "Sorry, something went wrong" message appears. By debugging, it can be seen that state (ConfirmResetPasswordState) has lost credentials and username required for state.confirmResetPassword() is empty string.

Screenshot 2024-08-13 at 8 40 43

Screenshot 2024-08-13 at 8 40 25

Note. Same problem appears when confirming signup.

@ruisebas
Copy link
Member

Hi @sasaar, thanks for reporting this.

We will take a look and post updates here.

@ruisebas ruisebas added the bug Something isn't working label Aug 13, 2024
@ruisebas
Copy link
Member

@sasaar I was unable to reproduce this issue when providing custom resetPasswordContent and confirmResetPasswordContent views to the Authenticator.
I tried both on the simulator and an actual device, and the component was able to proceed successfully.

credentials.username is set when the ResetPasswordState.username property is edited, so I suspect you might have something in your app that is causing the Authenticator to be re-drawn when the app either moves to the background or foreground.

For example, something sightly similar was happening when having an EnvironmentObject that automatically published a property: #52

@ruisebas ruisebas added question Further information is requested pending-community-response Issue is pending response from the issue requestor and removed bug Something isn't working labels Aug 16, 2024
@sasaar
Copy link
Author

sasaar commented Aug 20, 2024

Thanks for the advice, it indeed appeared that environment property forced view to refresh causing state (AuthenticatorBaseState) to be reinitialised.

@sasaar sasaar closed this as completed Aug 20, 2024
@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Aug 20, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-maintainer-response Issue is pending response from an Amplify team member question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants