Preview Deployments and SITE_URL for Convex Auth
I'm setting up Preview Apps for Vercel and I'm not sure how I can set the correct
SITE_URL
(Required for Convex Auth) because the URL is based on the git branch name, essentially dynamic for each preview app. What's the recommended way to set the SITE_URL
to the preview app? Otherwise, I'll need to manually set this every time. Not a big deal, but it would be cool to figure this out :).7 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Not quite a direct answer here, but I believe you can configure which URL to redirect to from your sign in page (e.g. make it
window.location.href
), and then provide the redirect
callback (https://labs.convex.dev/auth/api_reference/server#callbacksredirect) to allow redirects to any of your preview domains (I'm not sure how much better you can do than "is a subdomain of .vercel.app
" or whether you can securely detect that it's one of your preview URLs). The default behavior with no redirect
callback and to redirectTo
param is to redirect to whatever SITE_URL
is set to, and to error if ever trying to redirect to something at a different domain.
https://discord.com/channels/1019350475847499849/1305935235183022080 is also related if you're using Convex preview deployments to also preview backend changes, since you'll have a different callback URL for every preview. Looks like there's some tools out there to set up proxying, but IMO it might be easier to add simple email / password auth that's only available in dev / previewserver - Convex Auth
Authentication library for your Convex backend
Don’t mean to hijack the thread here, although I trust the OP may be interested in the answer too. Are there any plans for a Vercel integration so that we may have more seamless deployments?
If there’s a way to set the SITE_URL in convex for preview to something like NEXT_PUBLIC_WEBSITE_URL=https://$NEXT_PUBLIC_VERCEL_BRANCH_URL we’d be golden. Seems like a chicken and egg thing.
I was considering a fixed staging domain on Vercel but diminishes some of the DX advantages.
The Vercel preview deployment instructions in Convex docs have a line that seems relevant:
https://docs.convex.dev/production/hosting/vercel#how-it-works-1
It will set the CONVEX_URL (or similarly named) environment variable to point to the new Convex deployment.I haven't used Convex previews yet myself, but this seems to indicate that Convex is doing something behind the scenes for this exact problem. I may be misunderstanding it, though. Not sure what "or similarly named" means.
Thanks! I think the challenge here is the callback url for OAuth uses the CONVEX_URL, then the library uses SITE_URL post authentication to redirect to the front-end. So that’s the value which is perplexing.
Yeah, was hoping the "similarly named" bit maybe implied some inference or configurability, but I guess not
Thank you so much! I'll give the
redirect
callback a go!
Convex is doing something, yes. They will set the appropriate CONVEX_URL
. I'm actually not sure how it's detecting it, but it knows I'm using Expo, so it's setting it to PUBLIC_EXPO_CONVEX_URL
, which works well :). Convex Auth is separate and is the library requiring SITE_URL
to be set. But as @sshader pointed out above, you can override the behavior having to need SITE_URL
. I'll just manage it myself based on what env I'm in.
I believe it uses the HTTP actions URL, which is the .site
TLD as it registers HTTP actions for you. The SITE_URL
has to be different because that's where your app lives.