burnstony#1975
burnstony#19756mo ago

Convex Auth Prod

Have github and google convex auth working for react native app in DEV in PROD in prod I use the saem JWKS and JWT_PRIVATE_KEY as DEV and copied AUTH_GITHUB_ID, AUTH_GITHUB_SECRET, AUTH_GOOGLE_ID, AUTH_GOOGLE_SECRET from the respective sites SITE_URL https://www.everwhz.com on GITHUB set callback https://tame-condor-52.convex.site/api/auth/callback/github on Google added https://tame-condor-52.convex.site/api/auth/callback/google to the URI list The login pop up appears to work normally, but than the second sign in call doesn't work
29 Replies
burnstony#1975
burnstony#1975OP6mo ago
Just realized I am getting errors logged on convex dashboard Jul 19, 15:43:29 H GET /api/auth/callback/github error [TypeError: Invalid URL: 'http://'] Jul 19, 15:44:41 H GET /api/auth/callback/github error [Error: pkce cookie is missing.] getting the exact same errors for google as well
burnstony#1975
burnstony#1975OP6mo ago
Jul 19, 16:15:07 85 M auth:store success 28ms Jul 19, 16:15:07 85 A auth:signIn success 87ms Jul 19, 16:15:08 66 M auth:store success 20ms Jul 19, 16:15:08 66 A auth:signIn success 74ms Jul 19, 16:15:13 42 M auth:store success 24ms Jul 19, 16:15:13 42 H GET /api/auth/signin/* 302 91ms Jul 19, 16:15:14 6a M auth:store success 38ms Jul 19, 16:15:14 6a H GET /api/auth/callback/github error [TypeError: Invalid URL: 'http://'] Jul 19, 16:15:14 6a H GET /api/auth/callback/* 302 332ms Jul 19, 16:15:14 16 M auth:store failure 34ms Uncaught TypeError: Cannot read properties of null (reading 'toString') at sha256 (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:1360:0) at verifyCodeOnly (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:750:10) at handler (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:524:51) Jul 19, 16:15:14 16 A auth:signIn failure 78ms Uncaught Error: Uncaught TypeError: Cannot read properties of null (reading 'toString') at sha256 (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:1360:0) at verifyCodeOnly (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:750:10) at handler (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:524:51) at async signInImpl (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:1116:22) at async handler (../../../../node_modules/@convex-dev/auth/dist/server/implementation.js:445:20)
No description
No description
burnstony#1975
burnstony#1975OP6mo ago
I went throught the flow once and signed in, than when I try again and than click continue it jsut goes straight back to the SignIn page and I got the the above errors on the server side @Michal Srb any thoughts
Michal Srb
Michal Srb6mo ago
See https://labs.convex.dev/auth/config/oauth#production-setup, you cannot use the same Google and GitHub app between dev and prod
OAuth - Convex Auth
Relations, default values, unique fields and more for Convex
burnstony#1975
burnstony#1975OP6mo ago
I have two GitHub apps And the Google account is working in dev with convex and prod with clerk on with next.js
Michal Srb
Michal Srb6mo ago
The callback URL will be different for Convex Auth with prod deployment. Not sure about Clerk with next.js But the errors you’re getting are not good, I’ll look into what’s causing them
burnstony#1975
burnstony#1975OP6mo ago
yeah, I get this error, TypeError: Invalid URL: 'http://' but I am pretty sure I didnt set anything to 'http://'
Michal Srb
Michal Srb6mo ago
@burnstony#1975 did you already override the redirect callback? What does it look like?
burnstony#1975
burnstony#1975OP6mo ago
No description
Michal Srb
Michal Srb6mo ago
See https://labs.convex.dev/auth/config/oauth#add-sign-in-button and click on React Native, at the bottom it shows how to override the redirect callback. You are using RN right?
OAuth - Convex Auth
Authentication library for your Convex backend
burnstony#1975
burnstony#1975OP6mo ago
yeah I have auth.ts import { convexAuth } from "@convex-dev/auth/server"; import Google from "@auth/core/providers/google"; import GitHub from "@auth/core/providers/github"; export const { auth, signIn, signOut, store } = convexAuth({ providers: [Google, GitHub], callbacks: { async redirect({ redirectTo }) { return redirectTo; }, }, }); It works fine with DEV settings running inside Expo
Michal Srb
Michal Srb6mo ago
Ok that should work (although you definitely shouldn't leave it as is, as it's not secure)
burnstony#1975
burnstony#1975OP6mo ago
so it should just check that its one of the enumerated expected url's
Michal Srb
Michal Srb6mo ago
What is the redirectTo param in prod? (yeah it should check localhost / expo go, and then your prod web URL or mobile app URL)
burnstony#1975
burnstony#1975OP6mo ago
I am not sure, on github I set the callback url to https://tame-condor-52.convex.site/api/auth/callback/github
everwhz!
as it everwhz
Michal Srb
Michal Srb6mo ago
That's the callback URL. the redirectTo param is passed to the signIn function in your UI code
burnstony#1975
burnstony#1975OP6mo ago
one secodn
Michal Srb
Michal Srb6mo ago
The expo helper says you must configure the URL explicitly in prod, I think that might be it See docs on makeRedirectUri And another way to debug it is to add a console.log to the redirect callback in your auth.ts, and see what you're getting (I'm hoping it's "http://")
burnstony#1975
burnstony#1975OP6mo ago
const redirectTo = makeRedirectUri(); ... const { redirect } = await signIn(authType, { redirectTo }); authType = "github" await signIn(authType, { code }); it all works in dev. I am unsure how to see more logs in PROD
Michal Srb
Michal Srb6mo ago
What does "in PROD" mean for you? How are you testing your app "in PROD". I think you could: 1. Add the console.log 2. Deploy your convex code to your convex prod backend (npx convex deploy) 3. See logs in your prod dashboard
burnstony#1975
burnstony#1975OP6mo ago
I can see the convex logs in PROD but in DEV i can also see concole logs from the react native code but than I build using EAS either for TestFlight or a oreview build for the Simulator on Mac OS and I don't knoiw of a way to see those logs
Michal Srb
Michal Srb6mo ago
You can see Convex logs on your Convex dashboard
burnstony#1975
burnstony#1975OP6mo ago
yes I get this error for both github and google in PROD Jul 22, 14:31:27 H GET /api/auth/callback/github error [TypeError: Invalid URL: 'http://']
Michal Srb
Michal Srb6mo ago
Can you: 1. Add console.log(redirectTo) to the redirect callback 2. Deploy your convex code to your convex prod backend (npx convex deploy) 3. Retry the flow and see share what logs you get in your prod dashboard ?
burnstony#1975
burnstony#1975OP6mo ago
Thank you. I have to run now but I will try that this evening and let you know how it goes PROD log Jul 22, 14:44:34 H GET /api/auth/callback/github log 'redirectTo:' 'everwhz://' export const { auth, signIn, signOut, store } = convexAuth({ providers: [Google, GitHub], callbacks: { async redirect({ redirectTo }) { console.log('redirectTo:', redirectTo) return redirectTo; }, }, }) @Michal Srb that was easier than I thought in DEV Jul 22, 14:47:54 H GET /api/auth/callback/github log 'redirectTo:' 'exp://192.168.1.153:8081'
Michal Srb
Michal Srb6mo ago
@burnstony#1975 it should be fixed in @convex-dev/auth@0.0.39, please upgrade. Thanks for the report
burnstony#1975
burnstony#1975OP6mo ago
Amazing OK - that worked - thank you Its noticeably snappier as well - thank you @Michal Srb
v
v6mo ago
Common srb doubleu