Comments (9)
@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.
@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.
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.
@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.
@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.
@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.
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.
@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.
⚠️ 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)
- Version 2.25.7 & 2.26.0 have Package Resolution Failed HOT 5
- Cannot return null for non-nullable type: \'AWSDateTime\' within parent (/onUpdateImbybe/createdAt)" HOT 3
- Update aws-crt-swift dependency to fix a crash HOT 7
- Updating model attribute using Amplify.API.Query HOT 3
- visionOS AWSS3StoragePlugin Compilation Issue HOT 7
- Verification Codes are not sent for Amplify Auth HOT 5
- GraphQL API Bug HOT 5
- CUSTOM_AUTH_WITHOUT_SRP being ignored on configuration. HOT 5
- visionOS Sign In With Apple support for Cognito User Pools HOT 6
- Intermittent Session Dumping from Keychain on Unexpected Error in Amplify Auth HOT 18
- so many files “missing" HOT 5
- Improve the update application data documentation HOT 1
- Unknown errors HOT 7
- [DataStore.Flutter] Android sourced mutation not working on iOS with schema HOT 2
- Localization issues HOT 4
- DataStore cannot connect to model's sync subscriptions (AWS_LAMBDA auth type) HOT 1
- error Missing an expected key: 'NSPrivacyCollectedDataTypes' prevents generating Apple Privacy Reports HOT 6
- Created and deleted model on one device appears as created on the other HOT 5
- TaskQueue<Success> async execution is not serial HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amplify-swift.