https://supertokens.com/ logo
#support-questions
Title
# support-questions
w

web3geek

06/04/2022, 8:49 AM
Can I assign an email to an exisiting user? So I want users to sign up using the phone otp and verify email with OTP. how can I do this? later they can signin using either. passwordless
r

rp

06/04/2022, 3:37 PM
hey @web3geek . i don't think i understand the flow clearly. Can you explain again?
w

web3geek

06/06/2022, 4:10 AM
Hey @rp So what I have is first the user signups using phone and otp then I take their email. now I want to verify this email with otp. If I use the /code API with email it will generate a new user-id, right? So basically what I'm looking for is verify email with otp and make sure that it's assigned to the actual userId so he can later login with email or phone and we know it's the same user
r

rp

06/06/2022, 4:11 AM
Ah I see. To do that, you can associate the new email with the same user Id before generating the code.
There should be a function like Passwordless.updateUserInfo using which you can associate the email to this user.
So what you should do is, let the code be consumed and let it create a new user. Once the new user is created, you can delete the new user and associate the email with the existing userId.
And you can do all this via overriding of consumeCode API
finally, to prevent a new session from being created, you can check if a session exists in the api before calling the original implementation, and then add the existing session to the userContext object. Then in the createNewSession override, you can check if a session exists in the userContext and if it does, just return that existing session
If you want, I can send over some code for this in sometime
w

web3geek

06/06/2022, 4:17 AM
yes please. that would be great. thanks a lot
r

rp

06/06/2022, 5:39 AM
hey @web3geek
c

CaptainPhoton

06/30/2022, 9:16 AM
How would I use this? If I go to the login route it just sends me back to the app if I am logged in.
And if I log out then I don't have the session
r

rp

06/30/2022, 10:00 AM
@CaptainPhoton you can override the doesSessionExist function on the frontend (session recipe) to return false for the route on which you want to show the phone number input UI
c

CaptainPhoton

06/30/2022, 10:10 AM
Not sure I follow. Can I override it elsewhere than in the init?
r

rp

06/30/2022, 10:22 AM
you will have to override it in init
on the frontend
c

CaptainPhoton

06/30/2022, 10:27 AM
thanks I'll check it out!
userContext is empty in the doesSessionExist function :/ Setting it from the route like in the example:
r

rp

06/30/2022, 11:01 AM
Yea. You can set it like that
or in the override for doesSessionExistm you can check the current path of the url, and if it's /auth-info, then return
false
c

CaptainPhoton

06/30/2022, 11:02 AM
but it's empty 😕 input.userContext is an empty object here:
okay I'll check the URL then
r

rp

06/30/2022, 11:02 AM
which version of the supertokens-auth-react SDK?
c

CaptainPhoton

06/30/2022, 11:03 AM
0.23.2 I believe
r

rp

06/30/2022, 11:03 AM
right. That should work then
hmm
c

CaptainPhoton

06/30/2022, 11:03 AM
(it should return false there, I fixed it in the code)
r

rp

06/30/2022, 11:03 AM
so the doesSessionExist's userContext can be empty if it's being called by other places
c

CaptainPhoton

06/30/2022, 11:04 AM
I have to check the url then?
r

rp

06/30/2022, 11:04 AM
you can, but the context passing you did should work too
c

CaptainPhoton

06/30/2022, 11:05 AM
it would be nice
r

rp

06/30/2022, 11:05 AM
if it doesn't can you open an issue about it in our repo?
c

CaptainPhoton

06/30/2022, 11:05 AM
okay I'll do that!
r

rp

06/30/2022, 11:05 AM
thanks
c

CaptainPhoton

06/30/2022, 11:08 AM
It would be easier with a Supertokens interface where a logged-in user could change their email and phone number
or link to a thirdparty account
r

rp

06/30/2022, 11:09 AM
yea agreed. We will add them at somepoint for sure. If you like, you can open a feature request for this
c

CaptainPhoton

06/30/2022, 11:10 AM
would be great 😄
r

rp

06/30/2022, 12:03 PM
thanks! Will have a look
3 Views