Preview URL available during deployement
See original GitHub issueFeature 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:
- Created 3 years ago
- Reactions:10
- Comments:8
Top GitHub Comments
@vhiairrassary this could be a potential workaround:
https://vercel.com/docs/build-step#system-environment-variables
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 branchesstaging
anddev
served onmyapp.com
,staging.myapp.com
, anddev.myapp.com
respectively, then the environment variables (defined in Vercel Project Settings)will be exposed as
NEXT_PUBLIC_DEPLOYMENT_URL
on their respective branch deployments, which you can then use to configure redirect uris.