'redirect_mismatch' error with hosted UI
See original GitHub issueNote: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum
** Which Category is your question related to? ** Auth / Hosted UI
** What AWS Services are you utilizing? ** Cognito, Amplify Console
** Provide additional details e.g. code snippets ** Hi,
My auth work flow worked fine with the hosted UI when I was only using http://localhost:3000/ as the sign in/sign out url. When amplify console created a dev build, it hosted the frontend on a different url (https://dev.<some_id>.amplifyapp.com/ in my case). When opening the hosted UI from this url, it complained “redirect_mismatch”, which is understandable since I only have localhost configured in cognito at this point.
I ran amplify update auth
to add the console provided app url to the sign in/sign out urls, amplify push
then git commit
& git push
to make the amplify console pick up the changes. However, the console hosted app still gave me “redirect_mismatch” error. I checked the aws-export.js file and cognito console, the redirect urls are exactly the same (“http://localhost:3000/,https://dev.<some_id>.amplifyapp.com/”). I used Chrome’s inspection tool to check the actual redirect_uri
string in the HTTP request, also exactly the same. I have no idea why the hosted UI is complaining mismatch.
Then I found out the app stopped working on my localhost, too. Same “redirect_mismatch” error. 😦
Any help will be appreciated!
Issue Analytics
- State:
- Created 4 years ago
- Comments:29 (8 by maintainers)
Top GitHub Comments
Sorry guys but in fact, this is a normal behavior.
Setup
amplify add auth
with two URLs: “http://localhost:3000/,https://master.xxx.amplifyapp.com/” to add the sign in/sign out URLs,amplify push
thengit commit & git push
to make the amplify console pick up the changes.Then you get a
redirect_mismatch
error locally and online https://master.xxx.amplifyapp.com/Why ? There is no way for the react app. to know by default which URLs to use when you have two or more URLs. You must inform the app. to use one of these URLs. You can do it like that:
What can you do ? After looking in the doc., you find pretty much a solution here: https://aws-amplify.github.io/docs/js/authentication#react-components
and,
Full code & example You can find a demo here that also work in localhost: https://master.d3h5j4begww46c.amplifyapp.com/ And a github fork (from dabit3): https://github.com/arelaxtest/amplify-auth-demo
Personnally, I do something like
@jordanranz 's fix totally worked for me!
The correct solution is either that the SDK should handle this or the documentation should make a disclaimer about this snippet of code.