Hello, I have a specific question about UserIdMapp...
# support-questions-legacy
b
Hello, I have a specific question about UserIdMapping. I use ThirdPartyPasswordless recipe, which means that users can logIn from both of these with the same email. The issue I am facing is that my externalUserId is the same for both of these and my setUserIdMapping is violating the unique constraint "userid_mapping_external_user_id_key. Is there a way to remove this constraint, and is it safe ?
r
hey @binouse
right now, there is no way to remove this constraint as it's in the db level. What you are looking for is account linking which we don't support at the moment (but are working on).
In the meantime, you can change the external user ID of the duplicate email account to be "slightly" different (by adding some postfix to it). Then you can override all the functions in
ThirdPartyPasswordless
that return a userID to strip away that known postfix string from the userIDs before returning them.
b
Okay, and is it okay to remove the
userid_mapping_external_user_id_key
constraint manually ?
r
you can - but i would really suggest not to.. it might cause side effects in the future, especially if you want to upgrade the core at some point.
but yea.. as of now, you can. Should work fine
b
Thanks for your help 😃
Removing the constraint is causing an issue on getUserIdMapping as it has two supertokens userId for one external 😢 Core error:
Retrieved more than 2 UserId Mapping entries for a single userId.
I guess I have no other solution than your postfix one
r
Oh yeaaaa. That’s true. Had forgotten about that.
You could also form the core repo to remove that constraint and use the forked core 😅
Fork*
b
Hahah nah I wont do that, seems to be too painful 😅
The postfix is fine
r
Fair enough
b
Do you have an idea of when is the account linking feature coming out ?
r
1-2 months maybe
It’s quite complex from a security point of view. So it would take some time
But we have already made good progress on it. So shouldn’t be too long
b
Sounds nice 😊
Looking forward to it
r
👍
b
Hi, I'm sorry to bother you again, but I can’t think of a way to use the postfix solution. I can add a postfix like -pwdless, -google, -apple ... to the external userId but in my functions that call
getUserIdMapping
with the external userId, getUserById for example, I have no way of knowing which postfix to add because I don't know if the user is signing in via passwordless or any of my thirdparty provider. I don’t know if I am clear enough tho 😅
r
So you shouldn't have to change the input user ID in any of the functions like getUserById. The place where you need to remove the postfix is when you call the original implementation. That may give back a user ID with the postfix which you need to remove. For example, let's say you have user1@example.com using google with user ID "A" in your old auth system. You also have user1@example.com with fb login which is also mapped to "A" in your older system. Now in supertokens, you will create a google user with that email and map that supertokens user ID to "A". Then you will create a fb user with the same email and map that user's ST ID to "A". But that is not allowed. So instead, you should map it to "A-my-postfix" or something. Now when you override the recipe functions for example like getUsersByEmail, the original implementation will return a list of users who have that email. The user IDs in that will contain "A" and "A-my-postfix" - one for google, and one for fb. Here you should modify the user IDs to remove the "-my-postfix" part. Or for example, the sign in function which will return either "A" or "A-my-postfix" as the user ID depending on if the user used google or fb, and there too you want to remove the "-my-postfix" part. Now the only side effect of this is that when you use a function like
getUserById
and you give it "A", you will get back info only about the google user and not the fb user. To properly solve for this, we need to impl account linking. But until then, this may not be such a big problem anyway.
Hope this makes it clear.
b
Wow this works like a charm, I don’t event need to override anything as I am not using getUsersByEmail and my getUserById is always returning the user without the postfix
Thank you so much for your help !
r
Happy to help. That being said, I think you should override the functions to remove the postfix cause in the future someone in your team might use them and they may not know why it's not working then
b
That's right, I'll do that 😄
2 Views