Hey!!! There is a table named `userid_mapping `in ...
# support-questions
h
Hey!!! There is a table named `userid_mapping `in the supertokens core's database (when we are using self-hosted service). Could this table be used to map the user ids from supertokens database with some external NoSQL database, say MongoDB, which our application uses? Also, is there any table that can store additional session information that our application fetches?
r
hey @Himanshu Kukreja yea, this table can be used to map user IDs. Im not sure which SDK you are using, but in node, there is a function called
createUserIdMapping
which you can use: https://supertokens.com/docs/nodejs/modules/index.html#createUserIdMapping
about storing session info, you can store info in the access token payload or in the session data part.
h
Hey @rp after using the
userid_mapping
table (to store the supertokens_user_id and external_database_id), at the time of first-time signup (both third party and email password ) the user id that I get from` session.get_user_id()` or
session.user_id
is my supertokens id after the signup when we get logged out and again sign In we get the external database id. Why is this so?? Or Is there any method to override this change?
r
are you doing the mapping in the api override or in the recipe function override?
h
I was directly accessing the database
*userid_mapping
and making a SQL query call to it
r
thats fine.. but are you doing that in api override or function override? I mean, override.apis or in override.functions?
h
Oh yes. I am doing it in api override
r
right. You want to do this in the functions override
and also when you return the response from the functions override, make sure to change the user ID to the external one in the response object.
h
just to confirm I was doing it in
override_thirdpartyemailpassword_apis(original_implementation: APIInterface)
function but now I have to implement the mapping logic in
override_thirdpartyemailpassword_functions(original_implementation: RecipeInterface)
function
r
correct.
h
Ok right, Can you tell me which function I have to override by adding it into my mapping logic example
thirdparty_sign_in_up_post
or
thirdparty_sign_in_up
???
r
thirdparty_sign_in_up one
and also emailpassword_sign_up
h
I have implemented the mapping in
thirdparty_sign_in_up
and
emailpassword_sign_up
of
override_thirdpartyemailpassword_functions(original_implementation: RecipeInterface)
function but still the same problem persists thatis the at the time of first sign_up session.user_id givessupertokens_id while after logging out and then at the time of signIn session.user_id gives external_id. I am attaching my code snipped where I have implemented override_thirdpartyemailpassword_functions
At time of signup
But when we sign out and sign in then our user Id changes to my external database Id
r
do you modify the response object's user_id to point to your custom user in these overrides?
h
No we didn't changed response object's user_id because we are unsure that if it might have some affect in supertokens' internal code
r
you should modify that
before returning the response from the override
this will fix this issue
h
Yup you are right!!! the issue id fixed
Thank you so much, Its been a great help from you and thank you for assisting me and saving my life Your product is amazing like your support
r
great
h
Hey @rp , I have an issue with mapping function provided by supertokens. I have imported this function as
from supertokens_python.asyncio import create_user_id_mapping
. I have used this function inside the function overrides of
emailpassword_signup and thirdparty_signin_up
After the mapping I have used the api overrides in order to store the additional session information in my custom table. There is a problem of synchronizarion of this function (
create_user_id_mapping
) as in some cases mapping is done successfully before the calling of functions which I have written inside the api overrides while sometimes there is no mapping at the time of calling api override function. Thus it causes inconsistency. I am attaching the snippet of my code. Also If I uses the custom function for mapping, all things are running smoothly with no problem of synchronization
In the first snapshot the commented function is supertokens mapping function which I was using
r
you need to add
await
when calling the
create_user_id_mapping
function
h
I have added the await but the issue still persists
r
you may also need to add await for the mongo_db query that you are doing.
since the function is async
h
thnks issue resolved
r
cool