amplify-js: 'redirect_mismatch' error with hosted UI
Note: 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!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 33 (9 by maintainers)
Sorry guys but in fact, this is a normal behavior.
Setup
amplify add authwith two URLs: “http://localhost:3000/,https://master.xxx.amplifyapp.com/” to add the sign in/sign out URLs,amplify pushthengit commit & git pushto make the amplify console pick up the changes.Then you get a
redirect_mismatcherror 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
Same issue. I get
redirect_mismatchwhen using more than one redirect url@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.
@YangMann do you’ve a repro project you could share with us?
For folks on this thread – I recently experienced this issue myself and used the fix listed above. It works but I agree that our docs need to be updated and this should be fixed in the way the Amplify config state is created. This is now marked as a bug and will be addressed soon. https://github.com/aws-amplify/amplify-js/issues/5565.
Hi Guys, any plans on fixing this issue?
redirect uri populated from oauth.redirectSignIn at aws-export.js or Auth.configure({ oauth: {redirectSignIn: “…”} }).
i got the problem when using two redirect uris, change it to one uri fix my problem.
@attilah I have a question: how is the redirect uri populated when calling
Auth.federatedSignIn()?I wish the documentation updates soon. I was facing this issue too, and in my case, I had more than 2 domains. I followed this comment and tidy that up a bit to suit my needs. I hope the following solution can help someone:
Then you can call the
configureAmplifyin your AppCognito & Amplify should either not allow setting more than one URL, or they should handle it properly.
When you set more than one domain/URL, it could link to some documentation and this can have consequences. Imagine this happening for an app on production when they add another URL, and debugging this can be hard as this is not documented in the right way.
My Preview build fails with a redirect mismatch error, because it doesn’t update auth with the preview url. I don’t understand how Amplify doesn’t do this automatically. How do you update sign-in/sign-out redirect URIs headlessly?
Remember to add your redirect url to the facebook developer dashboard https://YOUR-DOMAIN.auth.us-east-1.amazoncognito.com/oauth2/idpresponse