Heroku: How to do login in Review Apps with Docker deploys?

  docker, heroku, next-auth, oauth, staging

I have login with GitHub in my app. Problem is that GitHub only allows you to set one callback url, and even if it did allow multiple I would need to set that callback in the release or postdeploy url. I don’t know if this is what I want to do (I guess I could make GitHub API calls to dynamically create multiple GitHub OAuth Apps for each Heroku Review App – I’d rather not do this).

Alternatively, since the review app database and the production databases are different, I could seed the database with dummy data and dummy users, but then I would need to somehow know during the Docker build stage that this app is meant to be a Review App (using HEROKU_BRANCH) so then I could add custom logic during build to disable the GitHub OAuth and accept only credential based login. Problem is that Heroku doesn’t supply the HEROKU_BRANCH or HEROKU_APP_NAME environment variables during the build stage. If I understand correctly they are only available during runtime and release stage.

I think I could currently on every request check if the HEROKU_BRANCH env var is set, but I would like to avoid run-time checks and create a different bundle during build.

BTW, I’m building an open-source Next.js app with NextAuth for authentication, but I’d appreciate platform/framework-agnostic responses too. If you’re familiar then I’d also appreciate how to conditionally change the way I accept login, I think using getStaticProps and check there for process.env.HEROKU_BRANCH is the best way, but again HEROKU_BRANCH is not available during build. For security I could also put a IS_HEROKU_REVIEW_APP just for peace of mind that someone setting the HEROKU_BRANCH env var will lead to some gigantic security issue.

My Dockerfile and heroku.yml.

Source: Docker Questions