Using nextauth discord with vercel deployments

New to T3 and nextauth here, and I have a noob question: If I configure discord oauth, discord requires me to register exact URIs for login redirects, but Vercel deployments have dynamic URIs for each branch, so a new branch deployment will never match. I can get any deployment to work by manually adding its URL to the discord app management page, but is there a way to make it work for any vercel branch? If not, do you have a preferred workaround/working style that you think is most effective? Maybe I should just use username/pw login for branches
6 Replies
dzenda
dzenda6mo ago
System Environment Variables Overview
Vercel Environment variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed.
dzenda
dzenda6mo ago
VERCEL_URL && VERCEL_BRANCH_URL
rdickert
rdickertOP6mo ago
Hey, thanks for the reply! I think the issue is not solveable from the env var side though - I think nextauth is already sending the matching login redirect, so that info is probably already being accessed by the package. The problem is that Discord won't recognize that URI - I have to input it manually in their dashboard and they don't accept wildcards. I did find a possible workaround using alias for anyone that runs into this. I think I will set this aside in my own work since this isn't central to my application.
GitHub
Google Auth 2.0 redirect URI with Vercel preview deployment · verce...
Google Auth 2.0 doesn't allow for use of wild card (*). How could I make auth work on my NextJS app for Vercel preview deployment when the url is dynamically generated, and Google wants hardcod...
dzenda
dzenda6mo ago
Oh I get what you mean
lanc3
lanc36mo ago
You create a proxy auth service like t3-turbo does. It basically just serves a static URI for your preview environments. I don't remember the exact logic, but you can just reference t3 turbo
rdickert
rdickertOP6mo ago
@lanc3 Oh wow, that's cool, thanks for pointing me there. For anyone following, here's the auth proxy
GitHub
create-t3-turbo/apps/auth-proxy/README.md at main · t3-oss/create-t...
Clean and simple starter repo using the T3 Stack along with Expo React Native - t3-oss/create-t3-turbo
Want results from more Discord servers?
Add your server