Rewrites/Redirects for AWS Amplify - reactjs

Can anyone help me with setting up rewrites/redirects?
I have a route that is /privacy_policy
With no rewrite, I get access denied only on the hosted app.
Then I found this solution for it: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
Added this to Amplify settings, and the page works fine. However, I have custom fonts in the directory that weren't loading in production.
I followed this: React images load locally but not on AWS Amplify
And changed the redirect from 200 to 404 rewrite. However, this then broke my fb login because fb curls my privacy policy and it returned a 404. How can I get both to work?

Related

AWS Amplify defaults cause Google Search Console to get Not Found 404 for page that loads fine

My site just started being indexed by Google. It was telling me that a subpage was throwing 404s. When I copy/paste the page into the URL bar, it loads fine. The issue was Amplify defaults for "Rewrites and redirects", which didn't work for my React/Router app.
The defaults Amplify gave me were 404's for <> and a regex that redirects non-html pages. I removed the <> and changed the other one to a 200 instead of 404, and now it works correctly. Screenshots of Amplify (broken and fixed, respectively):

Attempting to login using Auth0 and Netlify w/ React although I get "undefined" in the URL when trying to login

I wanted to deploy a react application which is a simple auth0 login page and on localhost:3000, eveything works fine, I can click the login button and everything works, it sends me to the auth0 login page.
Here is the part im stuck at:
When I push to Github and deploy to netlify and try to open it using the link netlify gave me, I click the login button and I get this in the URL bar: https://undefined/authorize?redirect_uri=
I have checked both the .env file in the app and on Netlify in the environments section and everything has the proper env variables. here is where I am testing it: https://reactjssample-324hz.netlify.app/
Here are the URIs I have setup:
Allowed Callback URLs:
http://localhost:3000,https://reactjssample-324hz.netlify.app
Allowed Logout URLs:
http://localhost:3000,https://reactjssample-324hz.netlify.app
Allowed Web Origins:
http://localhost:3000,https://reactjssample-324hz.netlify.app
Please tell me if I need to include anything such as code snippets.
EDIT: 06/01/2022
I have added the domain and clientID to the index.js file but now I am getting this when I click the login button:
Netlify 404 page not found although I have this in the URL bar now: https://tubular-klepon-a1d5fc.netlify.app/authorize?client_id= which I assume is better than what I had before.
EDIT: 06/02/2022
Here are the endpoint settings I have for my application
endpoint settings
Thanks
324hz
win1H2
he/him
Look like you have not configured the YOUR_DOMAIN in the application. Let try to configure it with value reactjssample-324hz.netlify.app
And do not forget to configure the customer domain reactjssample-324hz.netlify.app in Auth0 platform.
configure YOUR_DOMAIN
Hope it can help.

Firebase Google Authentication works on localhost, but not on Netlify hosted site

I have a React website that I'm hosting and deploying through Netlify. I have it currently set up so that I'm able to log in using their authentication service, which is useful. However, it only works on my Localhost. When I try to use it on the Netlify hosted site, I get the following error:
Uncaught (in promise) Error: Illegal url for new iframe - https://%22trail-app-7d2e3.firebaseapp.com%22/__/auth/iframe?apiKey=********&appName=%5BDEFAULT%5D&v=9.2.0&eid=p&usegapi=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.ILxaxn5iF9E.O%2Fam%3DAQ%2Fd%3D1%2Frs%3DAGLTcCP4GH4pdEaIiZe1k-cWfBRo9KTiAQ%2Fm%3D__features__#id=I0_1635906033796&_gfid=I0_1635906033796&parent=https%3A%2F%2Ftrailapp.netlify.app&pfname=&rpctoken=37134086
at Object._.Zk (cb=gapi.loaded_0:154)
at Fl (cb=gapi.loaded_0:165)
at Object._.Gl (cb=gapi.loaded_0:166)
at Object._.Nl (cb=gapi.loaded_0:172)
at _.Ym.openChild (cb=gapi.loaded_0:310)
at _.Ym.open (cb=gapi.loaded_0:315)
at iframe.ts:81
at l (runtime.js:63)
at Generator._invoke (runtime.js:294)
at Generator.next (runtime.js:119)
It seems as though it's trying to use that URL to reference a script that presents the iframe with the Google login. I'm not sure what permissions would be causing it not to work. I've enabled everything I know to.
I am using a .env file to hide my API information from a repository and have the values set up under "Environment Variables" on Netlify. If anyone has any feedback it'd be greatly appreciated!
You need to add your hosted domain in firebase as I have added my own domain here.

AWS Amplify ReactJS app trouble reloading page

I'm currently working on a full-stack project mainly using ReactJS and AWS Amplify. I've successfully deployed the website but the URL routings only seem to work if I redirect from the home page. I can only load the home page www.website.com but I try to manually type in www.website.com/login/, it gives me this message
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>B2173BDEE0658858</RequestId>
<HostId>
TRevHdaqGZYTUxU9W1wXc3CQccfLeznHlYLcbuF+Wr511FVmOPFBp4tpyccJ2t5QMVpvYygNNb4=
</HostId>
</Error>
I've looked up solutions from other StackOverflow pages but it didn't seem to solve the issue.
I have tried adding a redirect rule in the AWS console provided (Getting 403 ACCESS DENIED error when deploying React Web app on AWS Amplify) but the issue persists. Is there a way to fix this?
You have to set up a 404 (page not found) redirect on the AWS Amplify to point on the index.html.
React App is SPA (Single Page App) it has its own routing, and on the AWS side, all other routes except base path will return 404, because they don't exist on the server-side.
Once you setup 404 to points on your React application again, React router will handle the routing.
Check: docs.aws.amazon.com/amplify/latest/userguide/redirects.html and pay attention to 404 redirections.

Fixing 403 Access Denied Errors When Hosting a React Router App in AWS S3 with CloudFlare

I have a React App that is deployed on an S3 bucket.
When deploying a React Router app to S3, going directly to a React route will produce a 403 Access Denied error because S3 will try to look for an object in the bucket at that path.
Right now, we are redirecting all traffic to the index.html file, all the routes load fine, but first, we are receiving a 403 response, before the page loads. Which is causing a headache for Search Engines and SEO.
This can be solved by creating a custom error response in CloudFront that handles the HTTP 403 Response by responding with the index page and a 200 OK.
We are using Cloudflare as our CDN and switching to cloudfront at this point is not an option.
Is there a way to solve this problem using CloudFlare or S3 Configuration settings?

Resources