-
Notifications
You must be signed in to change notification settings - Fork 251
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
Merge Accounts in PreSignUp Trigger causes "Already found an entry for username" exception #1716
Comments
Hi @flodaniel - sorry you are experiencing this issue. Changing the following: await adminLinkUserAccounts({
username: cognitoUsername,
userPoolId,
providerName,
providerUserId,
}); to this: await adminLinkUserAccounts({
username: cognitoUsername,
userPoolId,
providerName,
providerUserId: userName,
}); seemed to fix the problem for me. Can you try that and let me know if you run into any other issues? |
Hi @dnys1 , thanks for the quick reply and specific change suggestion! While the changes fixes the immediate issue, it disables the intended behaviour. I now get two, unlinked cognito users, and when trying to reuse the email, which was initially used for sign up with google, for sign in with email, I have the same issue as without the lambda function --> The user cannot sign in, because he initially used google sign-in and in our database we only have the cognito userid of the google user. These are the two accounts created, which are not linked, and do not share the This is what we have in our database: Any other suggestions? :) |
Ah, sorry about that. I missed that difference between the two IDs. I will keep digging! |
I found a couple mentions of the same issue:
It looks like many people have implemented a front-end check to catch the error thrown and retry since it will succeed the second time. Not a great solution, and I will keep searching, but could be a way to work around the issue in the meantime! |
Okay, so this is a weird one. Here are my findings so far: w/out TriggersFirst, I tried to reproduce this without triggers and following the federation instructions in Cognito's docs. The flow for this is:
This works and creates a single user with the social provider ID in the identities map. Logging in with either username/password or Hosted UI returns the same Reproducing with TriggersThe problem seems to be that, with triggers, the only time you have knowledge of the social provider ID is after a sign in/up is already initiated when you really want it before the sign in initiates. So, to work around this, as others have suggested, you can throw a special error after calling Obviously, this is a suboptimal pattern from a UX perspective, and I will be asking the Cognito team their thoughts on this issue. However, in the meantime, this seems to be the only solution available (unless you know the social provider ID beforehand). p.s. if you see |
Thanks for doing your own in-depth research on this issue! Really appreciated. The hacky work around is not an option for us. We already have to deal with the overall bad experience with the hosted web UI instead of native dialogs, and further complicating that user flow is not really something we want to do. Will you report back in this ticket once you hear from the Cognito team? From what I have read so far the "Cognito Team" is the black hole for all bugs that are caused by the Cognito side and that will never be fixed - or no clear roadmap on when the fix is going to happen. For a paid service really disappointing. Again, appreciate your input and happy that the amplify team is doing a good job here! :) |
I will keep you posted on any developments. Please let me know if you'd like to brainstorm more alternatives in the meantime! |
hey @dnys1 , i am facing the exact same issue while using google login + cognito in a react web app. I am also using presignup trigger to merge the two user accounts and keep the sub same, let me know if you find any workaround this. |
Hi @aniketkambli - I'm sorry you are also facing this issue. At the moment, the only known workaround is the one mentioned above to catch a unique error thrown from your lambda and retry the login. |
same problem here. As amplify is designed to simplify AWS services usage it could be awesome to have in the federatedSignIn an option like |
btw - the workaround doesn't work. it might for Google (tho the error caught wasn't specific enough for us to distinguish), but certainly does not for Apple, FB, etc. |
We would also like to have this fixed. Currently having Google, Apple and Microsoft social login so the proposed work around will also not work for us. Please have this fixed, else more developers will decide to use Firebase instead of Cognito. |
Any updates on this? Any help required with testing? I used to be able to handle this on the client by catching the error and reauthorising (shout out to Bobby Hadz), but the error no longer contains 'Google', 'Facebook' etc. and more like the hash you provided above (
|
We also have a challenge now how to handle this in a nice way. We are thinking about using sessions storage to remember which social login button the user used. It's not great... |
@soplan yeah pretty much we’re landing |
This is an issue that needs to be fixed in Cognito itself. While it's on their radar, I have no information on when it might be fixed. |
@soplan even if u store what user clicked, don't they still have to oauth again? |
Yes but we do the reauth automatically. So the user will only see the screen flashing twice. It’s Terrible. I hate it. But the benefits for the user having the account linked is higher than the user getting into a new account and thinking we deleted their account or something else happened that erased their data. Knowing this about cognito, I would have chosen for a different auth provider. Migrating is not an option for us now. Too much work and risk involved in switching to firebase or another party. |
@soplan which oauth providers? when we tested - only google sorted of worked by calling auth again without user having to click thru. but even google did not work consistently. |
Hi @hanna-becker, there is currently an open issue in Android to fix this aws-amplify/amplify-android#1649. Unfortunately, I don't have a timeline on when that could happen. If you're able to, I would recommend trying our dev-preview rewrite which surfaces all lambda exceptions. While it is not currently production ready, we will be shifting our focus to development there and can prioritize fixes like this much quicker for our customers. Hope this helps! |
+1 to @dnys1's suggestion about the dev-preview version. If you are able to try it out, we would be interested in any feedback you have. Also, I just wanted to add a link to the issue in amplify-flutter where the Hosted UI & Lambda exceptions is being tracked - #1279. If you find any issues with Lambda exceptions and Hosted UI in dev-preview, feel free to leave feedback on that issue. You can read more about the developer preview release in the blog post and docs. |
@pierrick-libert-codeleap - I don't have a GitHub issue to link you to unfortunately. We do pass this feedback along to the Cognito team and they are aware it is something that customers are asking for. I unfortunately do not have a timeline on when it will be supported natively by Cognito though. |
I would also encourage anyone who is interested in seeing support for this feature to give the original issue description a 👍 . While hearing the individual use cases can be helpful, we use the number of 👍 reactions to an issue to get a quick idea of how much interest there is in a feature. |
For microsoft with openID it get worse If we are redirecting from microsoft userName sometimes looks like "microsoft_CAPITALsimplewith_Something" ` //providerUserId will be "1234Ca" PS. Just mentioning these because someone might save lot of time |
@frankleng What were some of the pitfalls you have to figure out when moving from Cognito to Firebase? |
it was a fairly straight forward transition. u can import existing user Ids into Firebase auth, and swap UI libs. user did not notice a difference, other than not having to auth twice. |
It is almost end of year and no solution found!? |
I have opened a support case with the Cognito team about this to get more info about the status of this issue and will edit this comment once i have received a reply. Edit: Overall they also referred to this being a "feature" that the cognito team is aware of, but they refused to give a timeline or any indication if they will ever work on it. For a product that we are paying for, this lack of transparency has been the most disappointing aspect so far. |
I just came across this issue, how is this still a problem? |
@slaat Yes this is still a problem in productive! I am really disappointed that amplify/cognito has no solution for such a basic need. Would we have known that, we would have used firebase auth. |
Is this issue fixed somehow ?? I was facing this exact issue since couple of days back and today I was testing and found it works ! Can we confirm if there is any changes deployed ?? |
Fyi @dnys1 @Jordan-Nelson |
Hi @nikvin15 I'm not aware of any changes deployed which should impact this. |
Cognito has recently resolved an issue with linking federated users to an existing user profile in Cognito User Pools. As a result, your Amplify application can now merge user identities from 3rd party social identity providers to a Cognito user in a user pool using the Pre sign-up Lambda trigger. You can use the
We will work on resources to share with you to explain how to integrate this feature into your Amplify app. |
I can confirm that my above implementation now works on the first try and we do not have to restart the authentication flow in the app anymore. Closing this issue. |
@flodaniel - glad to hear this resolves your issue! |
Can confirm also works for Google linking. Microsoft & Apple not. I hope cognito team pick this up as their next priority as firebase already supports linking these other social logins. |
Hi @soplan - what is the error you get for microsoft and Apple linking? can you please create a new Github issue so that we can track those specific failures? |
@abdallahshaban557 How do we set email_verified to true for Facebook social login now? As there is no attribute mapping available for email_verified in the case of Facebook, like many others I used this hacky workaround to set it to true each time the PostAuthentication lambda ran: With this issue fixed, we don't need to retrigger the auth flow on the client, which also means we don't enter that function any longer. However, setting email_verified to true in the PreSignup trigger doesn't work, unfortunately. I guess it gets overridden somewhere? So confused... |
Hi @hanna-becker - so the email_verified flag is being set to "false" after the linking is complete? Can you please create a new Github issue so that we can triage this further and raise it to the Cognito team if needed. That definetely seems like odd behavior. |
I raised a new issue on this and all other pain points I came across when implementing this: aws-amplify/amplify-js#11565 Everyone who ran into any of those issues, please upvote so that we get a better developer experience in the future. |
Description
When using the following PreSignUp lambda function to merge two accounts (OAuth and native cognito accounts), and allow users to use either options to signup, an exception is raised in the login flow, when the user initially creates their account. After the first sign up, the flow works as expected.
There are stackoverflow threads and blog posts on how to work around this issue, e.g. restarting the auth flow, or just not using
adminLinkProviderForUser
function:My PreSignUp trigger is based on: https://bobbyhadz.com/blog/aws-cognito-link-user-accounts
I use an entire custom flow to replace a password-based login with an OTP flow, based on this aws blog post https://aws.amazon.com/de/blogs/mobile/implementing-passwordless-email-authentication-with-amazon-cognito/
Exception:
AuthException(message: invalid_request: Already found an entry for username zPW8WMWZaBQLkE9JRMBkonMdvfI1WJ/Ds0K0pgQTM/g=, recoverySuggestion: Retry the webUi signIn, underlyingException: Der Vorgang konnte nicht abgeschlossen werden. (com.amazon.cognito.AWSCognitoAuthErrorDomain-Fehler -3000.))
PreSignUp Trigger lambda function:
Categories
Steps to Reproduce
Screenshots
No response
Platforms
Android Device/Emulator API Level
No response
Environment
Dependencies
Click to show
Device
iPhone SE
OS
iOS 15.5
CLI Version
7.6.22
Additional Context
No response
The text was updated successfully, but these errors were encountered: