How to set the generated vercel preview url as the env variable for NEXTAUTH_URL

Hello, so i have succesfully been able to create a github workflow that generated a new postgres db via a neon branch and a vercel preview deployment for every pull request I make and any subsequent commits to that PR. However I have noticed that NextAuth does not seem to be working because I have to set the NEXTAUTH_URL in my .env as the url of the generated preview deployment. And this url is random everytime it deploys. Also the I need the preview url to put into my env while building the app, but I can only generate the preview url after building the app. Has anyone encountered a similar problem, any advice on this would be greatly appreciated, thank you. I have also attached some images of my workflow, so hopefully that helps.
No description
No description
4 Replies
NotLuksus
NotLuksus12mo ago
https://vercel.com/docs/cli/env This might be what you are looking for, not sure if this could actually work as I never tried, but worth checking
Vercel Documentation
vercel env
Learn how to manage your environment variables in your Vercel Projects using the vercel env CLI command.
George
George12mo ago
Thanks for this, but I was not able to make it work, Can I ask how you have set up your github workflow? Also I have added a domain on vercel, that looks like this: "my-domain.vercel.app" . How do I use github action workflow to deploy to this specific domain. I am trying to setup a dev, dev-preview and prod environments, which will all have its own seperate databases on neon.
George
George12mo ago
I have tried to follow this, but I am having diffiuclty making it work: https://vercel.com/guides/how-to-alias-a-preview-deployment-using-the-cli
Vercel Documentation
How to Use Vercel CLI to Alias a URL to a Preview Deployment
Learn how to use the Vercel CLI to automatically alias a URL to a preview deployment.
NotLuksus
NotLuksus12mo ago
I haven’t build something like this yet. Regarding the domain you set up, that probably is your production domain, so whenever you merge main it will deploy to that. If you exactly know your environments there is no need to have a GitHub action to set all the variables and instead set up your branches manually once in vercel. If you want to have a preview with a seperate db for each feature branch the approach would probably be the following. 1. Get all deployments from vercel 2. find the correct one using commit id or something similar not sure what is actually received but there should be a way todo this 3. set the environment variables for that specific deployment Not sure how this would work since you need to set envelopes variables before the build for this to work and I’m not sure if you can do this by the default environment set up by vercel, if not you can probably still build around that using the deploy command and building your own pipeline for that
Want results from more Discord servers?
Add your server