question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preview URL available during deployement

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

While using @auth0/nextjs-auth0 we need to configure a redirectUri value (as part of the OAuth2 flow). Currently it is fixed, which means the authenticated pages from pull requests (automatically deployed using Vercel for GitHub) cannot be tested.

Workaround

But as each pull request has one of its preview URLs matching the following this pattern https://<project>-git-<branch-name>.<project>.vercel.app, we were able to workaround this issue by adding in Auth0 the following redirect URI pattern https://*.<project>.vercel.app and using the following code to deduce the redirectUri in our Next.js project:

if (process.env.NOW_GITHUB_COMMIT_REF === 'master') {
    baseRedirectUri = getConfig().publicRuntimeConfig.APP_URL;
}
else {
    baseRedirectUri = `https://myproject-git-${process.env.NOW_GITHUB_COMMIT_REF.replace('/', '-')}.myproject.vercel.app`
}

We consider this workaround to be a bit wobbly as not officially supported & as we rely on NOW_GITHUB_COMMIT_REF which needs to be transformed to get the Preview URL.

Describe the solution you’d like

The Preview URL ending with .<project>.vercel.app is available as an environment variable (something like VERCEL_PREVIEW_URL) during the deployment.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:8

github_iconTop GitHub Comments

3reactions
yegorkaycommented, Aug 10, 2020

@vhiairrassary this could be a potential workaround:

export const isProd = String(process.env.NODE_ENV) === 'production'
export const isDev = String(process.env.NODE_ENV) === 'development'

export const LOCAL_HOST = 'http://localhost:3000'

export const getProdPath = () => {
  const currentBranch = process.env.VERCEL_GITHUB_COMMIT_REF.toLowerCase()
    .replace('/', '-')
    .replace('_', '-')

  if (currentBranch === 'master') {
    return process.env.WEB_URI // we have a production URL env in the project we are working on
  }
  return `https://your-project${currentBranch}.vercel.app`
}

export const CONFIG_URL = isProd ? getProdPath() : LOCAL_HOST

https://vercel.com/docs/build-step#system-environment-variables

0reactions
lukeburnscommented, Jan 25, 2021

If your deployment is on a particular branch and is served from a custom domain, then you can use next-branch-env to define a deployment URL for each branch.

For example, if you have a production branch main and preview branches staging and dev served on myapp.com, staging.myapp.com, and dev.myapp.com respectively, then the environment variables (defined in Vercel Project Settings)

NEXT_PUBLIC_DEPLOYMENT_URL=https://myapp.com # production
STAGING_NEXT_PUBLIC_DEPLOYMENT_URL=https://staging.myapp.com # preview
DEV_NEXT_PUBLIC_DEPLOYMENT_URL=https://dev.myapp.com # preview

will be exposed as NEXT_PUBLIC_DEPLOYMENT_URL on their respective branch deployments, which you can then use to configure redirect uris.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preview Deployments – Vercel Docs
View, share and receive feedback on preview deployment URLs of your commits before you ... Preview Deployments are available by default for all...
Read more >
Preview deployments · Cloudflare Pages docs
To view preview deployments, navigate from the Account Home > Pages and select your project. Every time you open a new pull request...
Read more >
Configuring deployment previews | Cloud Run Documentation
This tutorial shows you how to use Cloud Run revision URLs to implement previews of GitHub pull requests through Cloud Build triggers. Previews...
Read more >
Deploy Previews | Netlify Docs
Deploy Previews work by deploying pull/merge requests to a unique URL different from the one your production site uses. This URL has the...
Read more >
Stable URLs for preview environments in Azure Static Web Apps
When you deploy a site to Azure Static Web Apps, each pull request against your production branch will generate a preview deployment available ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found