How do i use OAuth Providers with Expo React Native (Supabase v2)
Hey guys,
not sure how to use the OAuth providers in my expo react native app, I've seen some work arounds using expo-auth-session but this was for v1 supabase.
could anyone provide some code snippets that work?
55 Replies
this is the snippet for supabase v1 but im on v2 and cant find a similar snippet
is my best bet just to use v1?
If you've asked a question here, there is no need to double post in #off-topic. Someone using Expo will come along and answer, if there is no answer then it's just that no one using Expo is online at the moment.
@NVO After that you get the refresh token in the success response, then you can use it with setSession (https://supabase.com/docs/reference/javascript/auth-setsession)
@silentworks I think community members would be more patient, satisfied when sometimes the Supabase team also trying to help more actively. In general, none of the staff try to help under this section so it's not so surprising that someone try to get help also somewhere else. 🙂
This is a community run platform. I am a Supabase team member who is here but I don't know all technologies so can't comment on them. Patience has nothing to do with team members being present as others have waited to be answered or tried to work out the issue they are having while waiting.
@silentworks Oh okay I see. Then I misunderstand the use-case of this section. Let me ask one more question - I know it is not relevant to this expo topic but I think this is solved - so is there any section or platform where we (so the community) can get help from the team? There are some questions in what the community can't help but sometimes the answer would be important.
What kind of questions would this be? because It's more likely someone in the community has ran into this problem more than someone in the team. If its Supabase platform issue then you have the support menu in the dashboard or https://app.supabase.io/support/new
In example scaling when self hosting but I think there are a lot more. I remember this because I’d help me also a lot but none of these type of questions got answered.
That's quite a broad topic and I'm not sure anyone in the team is self hosting something that needs scaling. This is what I mean by someone in the community is more likely to experience this than someone on the team.
My point is that you are those who developing the system so you have all the knowledge how does it work and is there any way and if yeah to how to scale it.
Yet again scaling isn't a small topic and no one person can know what you are suggesting here. So the scenario would be more like multiple team members would have to leave their day to day to solve an issue that could potentially be 1 week to solve for 1 user. I don't think the example you gave is giving me a clear picture of where a team member's input would be more effective than a community member.
We build the tools and use them but this doesn't mean we use them in the same capacity as the community, because everyone's use case is different. A good case of this is Realtime stuff, @garyaustin has answered more questions relating to this than anyone in the team, because he has seen different use cases than we have in the team. He has even found issues that members in the team have never come across, at this point is where we can step in and help.
Hm I’ll check his answers then, thank you 🙂
sorry im not trying to spam you, but just trying to work through an issue, im sure you've been there yourself
im getting
would someone be able to provide a working snippet?
@futurmaster this is what im doing

this works on v1
ive set the auth/callback in my supabase dashboard and it works ok on v1
all ive changed here is setSession
FYI I'm using lodash in my code
thanks so much man
you are a legend
@futurmaster what is the project name from proxy?
like what should i set that to?
That comes from the expo side, the same as you named your project in the expo system
ok will give it a go
@futurmaster this is what my code looks like now

in my authentication tab in supabase

@futurmaster what version are you using in you package json perhaps the api has changed slightly?
is there something i need to do with my expo Linking config?
how are you getting the redirect to work on /
For which node module you mean?
supabase
i literally have no idea what im doing wrong
I’m not sure how you are using expo in your project. I’m using bare metal workflow so the configuration is a bit different than the normal expo managed workflow
okay
I’m using the v2RC version
ive pretty much just got a bare expo template with a simple linking config for expo web
although im not using expo wev
web
"@supabase/supabase-js": "^2.0.0-rc.8" - this is what I’m using
thanks i will give that a go
if not i will probably just work on other things and then hopefully some docs on oauth for expo / react native are written
because there is a quickstart guide for expo but its using the other sign in /sign up methods
its a shame the docs lack in this area
If you don’t get back any refresh token it means the AuthSession is misconfigured check that documentation
yeah i do get a refresh token
that part is fine
and im passing it to setSession
but it then errors out saying auth session is missing
i've logged it to console and i get a good response back from google oauth
Hm it sounds strange
Can you find the refresh token what you get in supabase? You can use the UI and there under the database choose auth schema
yeah let me have a look
yeah its in the refresh_token table
and the user_id for that token corresponds to the correct user in my oauth session
and when i click the sign in with google btn it redirects okay and then a new user is saved in the authentication -> users table
so the oauth part works okay i think... but the session is bugging out

Can you implement onAuthStateChange too and check this method with it? https://supabase.com/docs/reference/javascript/auth-onauthstatechange
onAuthStateChange() | Supabase
Receive a notification every time an auth event happens.
@futurmaster i have implemented it, it doesn’t not fire when logging in with oauth
it does fire when i sign in using regular sign in with password method
Ohkay got more stranger maybe that's the same problem why you get the error when trying to setup the refresh token. Which provider are you trying to use same as used by me?
i’m using google
@futurmaster your solution doesn't make sense according to typescript

its using a pick, which means it needs both of those fields in the object that is passed in as currentSession
and if you cmd click/ go to definition into setSession method you will see it needs and uses both currentSession.access_token and currentSession.refresh_token
Read the docs dude: https://supabase.com/docs/reference/javascript/auth-setsession
setSession() | Supabase
Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
Hi :vmathi: I'm kinda confused about this discussion. Did you have a look in this guide? Could be a way to answer your question: https://supabase.com/docs/guides/with-expo
Quickstart: Expo | Supabase
Learn how to use Supabase in your React Native App.
Hi @Olyno, unfortunately not because this topic is more related to social auth under expo
Isn't it what he was asking for?
@Olyno he wants to know how to make Google OAuth working with supabase v2 js client in an expo project. The description what you linked are very detailed but unfortunately only the username/password auth type are used in it.
Well, the Supabase SDK is not exclusively limited to only username/password auth. You can use the
signInWithOauth
method instead of the username/password one
The main issue i see here is how to setup Supabase with Expo, but this part is explained in the guide. When the question is more about how to use the sdk, there is already a lot of documentation about it :pOnly for the v1 and not for v2 that’s the main problem 🙂
Right now I’m only using Facebook auth but will to implement Google too after that maybe could help more in this problem
I'm still confused by the problem here 😂
Is it what you're looking for? https://supabase.com/docs/reference/javascript/auth-signinwithoauth
signInWithOAuth() | Supabase
Log in an existing user via a third-party provider.
Unfortunately this doesn't work in a react native application. In the v1 's doc you can find a working solution for oauth in a react native (expo) environment but there isn't any working example in the v2 version's doc.
(Here is the old - v1 - approach: https://supabase.com/docs/reference/javascript/v1/auth-signin#sign-in-using-a-refresh-token-eg-in-react-native)
signIn() | Supabase
Log in an existing user, or login via a third-party provider.
You would just replace
with
for it to work with v2
This function is not in the documentation as yet but there is a PR to get it in soon https://github.com/supabase/supabase/pull/9839
GitHub
docs: add refreshSession() by j4w8n · Pull Request #9839 · supabase...
What kind of change does this PR introduce?
Updates documentation for new refreshSession() method.
@silentworks thats a lot will give this a try
... when its released
scary thing is, i dont know why it works...
i think its because i didnt have my linking configuration set up to handle the redirect uri
Deep linking is something else and not the same as authsession do
It means you can handle the same path in both cases the deep linking won’t matter here