Coder Social home page Coder Social logo

Comments (9)

harsh62 avatar harsh62 commented on June 12, 2024

@LarissaKim Thanks for raising the issue. From the steps that you listed out, I didn't see you performing a Sign In step. To fetch or update user attributes, the user needs to be signed in first.

If the user is signed in and you are seeing the issue, would you be able to share the error output and verbose logs when the issue happens.
You can enable verbose logging to the console by doing this before calling Amplify.configure:

Amplify.Logging.logLevel = .verbose

from amplify-swift.

LarissaKim avatar LarissaKim commented on June 12, 2024

@harsh62 Yes, that would be because when I attempt to signIn the user when confirmSignUp is successful, I get the AuthError "There is already a user in signedIn state. SignOut the user first before calling signIn".
This seems to indicate confirmSignUp automatically signs in the user?

from amplify-swift.

harsh62 avatar harsh62 commented on June 12, 2024

This is really strange..

This seems to indicate confirmSignUp automatically signs in the user?

Amplify doesn't have this kind of a feature built in.

"There is already a user in signedIn state. SignOut the user first before calling signIn".

Did you ever in your testing try the sign In API and got actually signed in (with an app that has the same bundle identifier). This could result in credentials getting persisted in the keychain and Amplify thinking a user is already signed in.

Could you share some logs, when running API's?

from amplify-swift.

LarissaKim avatar LarissaKim commented on June 12, 2024

@harsh62 I've actually been in the process of verifying if fetchUserAttributes and updateUserAttributes works during the signIn flow to ensure this was only a problem during the signUp flow.

After creating the new user, I stopped the simulator then re-ran the app. I was able to successfully sign in to the app, and also successfully completed fetchUserAttributes. I stopped the simulator again (without signing out), and re-attempted to sign in again to test out updateUserAttributes, but it seems the credentials are getting persisted in the keychain because Amplify.Auth.signIn is resulting in an AuthError for invalidState with the message "There is already a user in signedIn state. SignOut the user first before calling signIn.".

I'm trying to verify if force signing out then signing back in resolve the issue, at least for the sign in flow. Will update with logs shortly.

from amplify-swift.

harsh62 avatar harsh62 commented on June 12, 2024

@LarissaKim The Amplify session is persisted across app launches, and would only be removed once sign out is called. It feels like your use case can utilize the fetchAuthSession API to check if there is a valid user signed in. You should only ever call sign In when you know there is NO user signed In. Following is the code snippet I envision you would need:

   func fetchAttributes() async throws {
        if try await checkIfUserIsSignedIn() {
            let userAttributes = try await Amplify.Auth.fetchUserAttributes()
        } else {
            // call Amplify.Auth.signIn again and call fetchAttributes method
        }
    }

    func checkIfUserIsSignedIn() async throws -> Bool {
        let session = try await Amplify.Auth.fetchAuthSession()
        return session.isSignedIn
    }

from amplify-swift.

LarissaKim avatar LarissaKim commented on June 12, 2024

@harsh62 I'll try that out and see if it works for the sign-up flow as well. Curious that the user is automatically signed in during confirmSignUp, though.

Would Amplify.Hub.publisher(for: .auth) provide the state of the Amplify session across app launches, or are these events only emitted as a result of app-initiated operations?

from amplify-swift.

harsh62 avatar harsh62 commented on June 12, 2024

As I said earlier, confirmSignUp will not automatically sign in the user. Amplify doesn't have a feature like that. If that is happening, I would be curious to see the verbose logs and observe what is really happening.

Hub events are resultant of App initiated operations. Hub events won't be triggered on app launches.

from amplify-swift.

LarissaKim avatar LarissaKim commented on June 12, 2024

@hard62 Thanks for the clarification on the Hub events.

Interestingly, the issue has resolved itself. I no longer get the AuthError "There is already a user in signedIn state. SignOut the user first before calling signIn" when calling signIn after calling confirmSignUp, and I'm also able to call Amplify.Auth.fetchUserAttributes and Amplify.Auth.update(userAttribute: AuthUserAttribute) without any errors.

The only thing that was changed was adding the suggested Amplify.Auth.fetchAuthSession check when fetching the attributes, everything else including the Cognito User Pool configuration and Amplify configuration are the same.

I will re-open the issue with logs should the issue reappear. Thank you for your time.

from amplify-swift.

github-actions avatar github-actions commented on June 12, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

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.

from amplify-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.