Supabase Auth and Convex
Hey everyone! I've been trying to setup Supabase auth to be used with Convex (their free tier is more appealing than Clerk) but I've not been about to get it working, It errors out
Uncaught Error: Not authenticated
This is for a React Native
mobile application.
I changed the auth.config.ts
to
From there I have a hook useSupabaseConvexAuth
which is then used in my _layout.tsx
I've set the env variables on the Convex dashboard and have my Supabase public and private keys.
Any suggestions or feedback on how I could get this setup? I can sign into the app and log the access_token, but it appears to not be making it to Convex.13 Replies
type
and key
in your auth.config.ts
aren't valid properties, are you seeing them documented somewhere?For the
auth.config.ts
that was taken from chatGPT. I've seen them referenced here: https://labs.convex.dev/auth/setup/manual
https://docs.convex.dev/auth/advanced/custom-jwt
What should the keys be updated to?There's no
key
, type
can be set to customJwt
to avoid setting up an oidc provider, as that last doc you linked shows
If supabase auth does oidc, you only need applicationId and domain
domain
should match the iss
claim, applicationId
should match the aud
claim
Someone here is saying they don't actually implement full oidc, as they don't expose well-known endpoints: https://github.com/orgs/supabase/discussions/6547#discussioncomment-9049664
May or may not be accurate
But if that's true, that customJwt doc you linked would be your path forward, as long as you can find the jwks endpoint that supabase auth uses
All of that said, have you considered just using Convex Auth?
I suspect there may be more hiccups on the path of using Supabase Auth, but if that's what you're set on I'll def help however I can.I'll have to dig into the supabase stuff more. Their own documentation isn't even correct. It says to enable OIDC via a menu, that is no longer present
I have considered using Convex Auth and went through this setup for React Native: https://labs.convex.dev/auth
I hit a few hiccups after getting this setup implemented
If you wouldn't mind me hitting you up with a few questions I'd be down for trying to smooth out the implementation on my end. I feel it would be easier than this
For sure - I've used Convex Auth with Expo in production, happy to help
I really appreciate that! Thank you 😃 would you like me to DM you or keep it all in this thread?
After going through that setup guide, how did you handle checking if a user had signed in or not and redirecting to a /login page or showing content? For example on supabase I just made a hook
Then in my _layout.tsx inside (tabs)
Are you making hooks to interact with convex's auth or is it all functions that are added to the convex directory?
We can keep the discussion here, makes it discoverable for others in the future.
All I use:
You can redirect based on those statuses
If isLoading, the authenticated state might still change, so you want to wait until isLoading settles to false.
Went through the project setup again via the Convex Auth documentation. I am doing OTP (OAuth will be later)
I followed this guide: https://labs.convex.dev/auth/config/otps
It encounters an error validating the code
Here is the SignIn.tsx for reference
Pretty sure I got this part cleared up. Im trying to just retrieve data about the logged in user from the
users
table
Is getUserIdentity
correct in this instance?Yeah that's right, but just use the _id and get the rest from the database to keep the query reactive
Do we also need to define the users table in the schema.ts?
https://docs.convex.dev/auth/database-auth
I've defined it based on this and modified the function to this
But it seems this way you have to store the tokenIdentifier or you can't query a user
Got this one working!
When you mention to keep it lean, since the _id shouldnt change once a user registers what if we do a hook to get the user
Then cache that userId with a useQuery and use it for future functions? or should we just call it each time in the function? It seems to be relatively inexpensive.
You want to call it each time in case the authorization changes
What would you recommend when writing functions to retrieve data for a user, should we store the
_id
in those records, lets say its a list of ToDo's, to retrieve them for the authenticated user would you use that id or is there a better way fetch data?That's exactly how you'd do it 👍