Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an "Access Denied" error when I reload my React app on AWS Amplify

I am working on a React app that's running on AWS Amplify. My React app is using the react-router-dom library to route to different components. After running amplify publish in the CLI, at the root of the app (obktraining.com) everything is fine in the browser, I can also route to other components in the app just fine as well. But when I refresh my browser while I am on a route (obktraining.com/menu), I get an Access Denied error message.

I have found other posts about similar issues regarding rewrites and redirects in Amplify, but the solutions given do not work for me.

Here is an image of the error: enter image description here

My Amplify app rewrites & redirects : enter image description here

Again, the error only displays when I refresh on a route (obktraining.com/menu or obktraining.com/drinks) not on obktraining.com. Is the issue being caused by the react-router-dom library or is it an issue with Amplify settings? I am not sure where to go from here.

like image 825
Justin Avatar asked Jul 22 '20 02:07

Justin


People also ask

Does AWS amplify work with React?

You have deployed a React application in the AWS Cloud by integrating with GitHub and using AWS Amplify. With AWS Amplify, you can continuously deploy your application in the cloud and host it on a globally available CDN. Next, we will create a local version of the app to continue development and add new features.

How do I add an amplify React?

To get started, first create a new React app, and then install and use the Amplify CLI to start adding backend capabilities to your app. This creates a new React app in a directory called react-amplified and then switches into the new directory.


1 Answers

I have been facing the same error since days.The error is being caused by the amplify settings. The solution is simple, Edit your Rewrites and redirects by adding a new rule.

source address = </^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>

target address = /index.html

status = 200 (Rewrite)

Country code can be left blank

Save and try refreshing your app again. It should probably work.

use this for reference: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa

like image 177
Dhruv Godambe Avatar answered Sep 19 '22 13:09

Dhruv Godambe