aws-amplify / aws-amplify/amplify-hosting

Preview deploy doesn't update redirect URLs

Open
#2,108 4 comments 1 reaction 0 assignees View on GitHub
web-previews
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-console/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-console/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-console/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### App Id

dazj4he0xk1lv

### Region

us-east-1

### Amplify Console feature

Previews

### Describe the bug

I enabled Previews, created a PR, and deployed it successfully. However, when I go to its URL, it redirects to login and then redirects again with a URL mismatch error, because while initializing the environment, it didn't update the redirect URIs, so Cognito stays outdated, with the configuration it derived from the production environment.

I should point I wasn't able to find an existing issue, which is very odd, given the fact it's a popular feature. I did have to swap out the default `amplifyPush` with my own (which I simply grabbed from this repository), to overcome issues like a missing Google parameter, failure to find existing environment, etc'.

### Expected behavior

Update OAuth redirect URIs with the newly created deploy subdomain URL.

### Reproduction steps

* Enable Previews
* Deploy

### Build Settings

```yaml
# https://docs.amplify.aws/cli/usage/headless
# https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html
# https://github.com/aws-amplify/amplify-console/issues/176
# https://github.com/aws-amplify/amplify-console/issues/229
# https://github.com/aws-amplify/amplify-console/issues/1642
# https://github.com/aws-amplify/amplify-console/issues/1330#issuecomment-739493860
version: 1
backend:
phases:
preBuild:
commands:
- yum update --assumeyes
- yum install --assumeyes jq
- echo "JQ_VERSION="$(jq --version)
- node ./scripts/update_amplify_config.js
build:
commands:
- '# Execute Amplify CLI with the helper script'
- chmod u+x ./scripts/amplifyPush.sh
- ./scripts/amplifyPush.sh --simple
frontend:
phases:
preBuild:
commands:
# - nvm install 14
# - nvm use 14
# https://stackoverflow.com/questions/58482655/what-is-the-closest-to-npm-ci-in-yarn
- yarn global add ts-node
- rm -rf node_modules && yarn install --frozen-lockfile # equivalent of `npm ci`
build:
commands:
- yarn build

artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- ~/.cache
# - node_modules/**/*
test:
phases:
preTest:
commands:
# https://docs.aws.amazon.com/amplify/latest/userguide/running-tests.html
# https://aws.amazon.com/blogs/mobile/run-end-to-end-cypress-tests-for-your-fullstack-ci-cd-deployment-with-amplify-console/
# https://github.com/aws-amplify/amplify-console/issues/583
# https://github.com/aws-amplify/amplify-console/issues/240
# https://github.com/cypress-io/cypress/issues/6960
# - export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# - fs.inotify.max_user_watches=524288
# - yarn global add pm2 mocha mochawesome mochawesome-merge mochawesome-report-generator
- yarn pm2 start 'yarn start:test'
- yarn wait-on http://localhost:3000
test:
commands:
# https://docs.cypress.io/guides/guides/command-line#cypress-run-config-lt-config-gt
- 'yarn cypress run --config watchForFileChanges=false --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- yarn mochawesome-merge cypress/report/mochawesome-report/*.json > cypress/report/mochawesome.json
- yarn pm2 kill
artifacts:
baseDirectory: cypress
configFilePath: '**/mochawesome.json'
files:
- '**/*.png'
- '**/*.mp4'
```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing scripts/update_amplify_config.js and scripts/amplifyPush.sh during a preview deployment, then inspect how the Cognito configuration derives its redirect URIs. Reproduce the login flow with the provided preview settings; done means the deploy subdomain is included in the OAuth redirect URIs and no URL mismatch occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, shell
Domain
authentication, ci-cd, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.