Open ChartistDev opened 1 month ago
Hello, @ChartistDev and thanks for opening this issue. Just to be clear, Amplify.configure()
should be called as early as possible in your application’s life-cycle. It's possible that if you call it multiple times it could lead to potential race conditions due to the way the Amplify singleton behaves.
That being said, I believe the best way to ensure that you're properly getting the credentials/config you're looking for in this scenario is to ensure that before calling signIn()
or other API's... call Amplify.getConfig()
another time after your final configureAmplify()
call to validate that the userPoolClientId
exists and is valid.
Can you clarify if you are modifying or reconfiguring and calling Auth API's in different React component cycles? Or can you possibly describe a little more about the use case you're looking for here tied to, "getting the userPoolClientId dynamically and I need to set it before signin and reset it in case of any error"?
Hey @cwomack thanks for replying. So I have different userPoolClientIds set in AWS based on different emails.. Its got to do something about people from different organisations. Also Frontend React is not aware of what those Ids may be. So in the signin page , before the actual signin API, I call a different internal API with the email as my payload. This response gives me the relevant UserPoolClientId. Using that I need to reconfigure Amplify before I call the signin API. Also conversely if the signin fails (lets say due to incorrect passoword) I need to reset the Amplify config so that its ready to take the config the next time I want to signin with a valid email
@ChartistDev , For the following,
I have different userPoolIds set in AWS based on different emails.. Its got to do something about people from different organisations
I think best bet would be to keep a map somewhere and use it. As indicated by Chris, because Amplify config is a singleton, configuring that on the go could lead to race_conditions and other unforeseen issues. It is not recommended by us.
@ashika112 Hi.. I didn't get u.. what is meant by keeping a map? Does that mean we can't reconfigure and have to use only one UserPoolClientId?
@ChartistDev, can you help us understand why you're needing, "different userPoolIds set in AWS based on different emails"? I want to make sure that we are giving proper guidance here based on the use case you're looking for because we might be able to accomplish this goal in other ways (within the same user pool).
Hi @cwomack different accounts have different authentication methods: some use email/passwords, some use SSO(Single Sign On) if they use email password, we can manage with a single client but when they use SSO, we need to redirect login to SSO provider only but if the same client has all the SSO options added, SSO information of other accounts will be visible to all accounts So we maintain multiple accounts for a single client we will call the internal API with email as payload and it gives me a userPoolClientID and if that client ID has SSO enabled for other accounts also, it will return that information as well, which can lead to information leakage which is why we add different SSO providers to different clients, and link a client to an account.
@ChartistDev, can you clarify what you mean by if the same client has all the SSO options added, SSO information of other accounts will be visible to all accounts
? Is this a user pool client or possibly a business client? I'm still not understanding why there would be information returned for other accounts here.
@cwomack Perhaps I can help with the explanation here.
We use different user pool clients to allow different business clients to log into the same cognito user pool.
Each business client has different a different sign-in provider. If we enable all providers within one user pool client, then any business client could potentially access the sign-in providers of other business clients. Which is why we create a separate user pool client for each business client.
Edit: I am working with @ChartistDev on the same project.
@ChartistDev and @kartikay-bagla, appreciate the responses and additional context provided. After reviewing this internally, we're going to mark it as a feature request to have support for dynamic configurations (that currently cannot be done with the Amplify singleton).
Thank you @cwomack
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth, storage
Backend
None
Environment information
Describe the bug
I am getting the userPoolClientId dynamically and I need to set it before signin and reset it in case of any error. I am resetting it with this command:
But when I'm trying again to login via valid credentials the internal config JSON is still having undefined The weird thing is the Cognito API call is sending the correct payload and I've even logged the current Amplify instance on console and its fine
Expected behavior
Amplify config JSON should reset when I'm sending the configure call.
Reproduction steps
I am attaching the screenshots here:
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response