dabit3 / gatsby-auth-starter-aws-amplify

Starter Project with Authentication with Gatsby & AWS Amplify
MIT License
324 stars 399 forks source link

Refreshing a route while logged in redirects to index.html #27

Open CaptainChemist opened 4 years ago

CaptainChemist commented 4 years ago

I'm running into an issue with redirects when I deploy this app. The issue is that when I am logged in and reload the page, I get redirected to index.html which then redirects me to the home page. The expected behavior is that reloading the page should maintain the current route.

Steps to reproduce: 1) Log in 2) go to /app/home 3) Reload the page 4) App redirects user to / route which forces the user to have to navigate back to the /app/home to get where they were.

I made a video which documents this behavior: https://www.youtube.com/watch?v=3rhpsWgAX3s

I played around with this and the behavior can be "fixed" by changing the 404 redirect to a 404 rewrite, but it has the negative consequence that none of the meta tags load and it shows up to facebook link debugger as a 404 error (in contrast to the default behavior where it all loads correctly). So that's to say that the 404 rewrite change probably isn't a long term solution.

Any ideas how you'd go about fixing this? Thanks so much for contributing this demo repo Nader, it's really great!

devnantes44 commented 4 years ago

I've got a similar problem although with a slight difference:

  1. Log in
  2. go to /app/home
  3. Reload the page
  4. App redirects user to / route then redirec to /app/home

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

Were you able to handle this issue @CaptainChemist ?

CaptainChemist commented 4 years ago

@devnantes44 No, I wasn't able to solve it unfortunately.

mtliendo commented 4 years ago

@devnantes44 @CaptainChemist have you both had a chance to go through the above link and if so, is the issue still happening?

CaptainChemist commented 4 years ago

@mtliendo I just tried having the following be my only redirect and I can confirm that this did not fix my problem and in fact made it worse. So that documentation provided did not work in my case unfortunately.

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

Previously, I could directly navigate to pages that was not a protected route and I would not be navigated to the home page, it was only protected pages that would get navigated back to the home page regardless of whether the person was logged in or not. I think for me personally, even though the expected behavior should be that I can see pages that I should be able to see even if I refresh the page without a redirect to the home page, as long as my public pages act like they should, I can work around that.

source address: /<*> target address: /index.html type: 404 (Redirect)