https://supertokens.com/ logo
Webview login with react native
l

Leander

03/23/2023, 9:32 AM
Hi i'm curious about whether or not i should create native login or use my existing browser flow (kinda want to just reuse my browser logic), and how that might work regarding session for browser, but header for mobile. Using react native.
n

nkshah2

03/23/2023, 9:37 AM
Hi @Leander , One way to do this would be to first enable JWTs for the session recipe (you can refer to the docs for this). After you complete the sign in flow in the webview and have a session created you can send the JWT to native. Native would then call another API (say
/createsession
) sending the JWT
The API verifies the JWT using the JWKS flow (explained in the docs) and reads the user id from it
And then you can create a new session for that user id which will use headers instead of cookies
l

Leander

03/23/2023, 9:39 AM
okey thx, that sounds like it should work 🙂
n

nkshah2

03/23/2023, 9:40 AM
Happy to help, let us know if you run into issues setting it up and we can help out
l

Leander

03/23/2023, 9:41 AM
sidestep: is there a clean way to exit webview once login is successfull?
n

nkshah2

03/23/2023, 9:42 AM
By exit you mean close or logout and close?
l

Leander

03/23/2023, 9:43 AM
just close the webview and go back to the app
n

nkshah2

03/23/2023, 9:44 AM
Is this going to be an in app webview or launch the browser?
l

Leander

03/23/2023, 9:45 AM
im only using the webview for the login/signup process
- the webview is in app
n

nkshah2

03/23/2023, 9:50 AM
You could conditionally render the webview
{
    shouldShowWebview && <Webview />
}
And toggle
shouldShowWebview
to false once the login process is complete
That should dismiss it (with the exit animation if im not wrong)
l

Leander

03/23/2023, 9:51 AM
i'll test it out! appreciate your help.
n

nkshah2

03/23/2023, 9:51 AM
Happy to help