Redux bug putting html into user login object

I’m having an odd error when loading the site it is automatically loading a user and logging them in, however it’s not an actual user it’s loading the html into the user object and I’m not sure where it’s coming from. This hasn’t happened anytime before on a dev environment or on another deployment site. Any help or insight to this problem would be greatly appreciated - Thank you.

Hi @Joe1542,

A website name or URL could help us check. Mind sharing it?

Sure thing, https://practical-ride-4eaafa.netlify.app/
I noticed that it’s sending a http request to https://practical-ride-4eaafa.netlify.app/api/auth/user but I just changed the proxy so that it would send the request to my backend server, I can see that’s why the request is returning the html instead of the actual request data. Do proxies not work in Netlify?

Hi, @Joe1542. This site doesn’t use any proxies. I see there is a single redirect in the deploy below:

https://app.netlify.com/sites/practical-ride-4eaafa/deploys/6137c36a32a08f0007561cf3

Quoting that page:

  • 1 redirect rule processed

All redirect rules deployed without errors.

However, when I download the deploy the only redirect is the one below found in the file _redirects:

/* /index.html 200

I’ve checked all of the deploys for that site and none of them contain any proxy redirect rules.

So, I believe issue we should be troubleshooting is: “Where you are adding the proxy redirect and why it isn’t being detected?”

Where are you adding the rule? Have you added it to _redirects or netlify.toml? Are you sure the file is being placed in the publish directory for this site (which is client/build in the most recent build)?

You’re correct, I have a proxy setup in my own code which switches out the url for a different url to make the http request. I did do some research on my own and I found out that Netlify uses the _redirects to make these calls as well which would be something like this

/api/* my.domain.com 200

That being said if I have my routes setup like this axios.get(‘/api/user/getUsers’) how would I setup the redirect in _redirects for that? Would it be /api/* my.domain.com/api 200? Also since all of them are setup like that would I have to include more redirect rules for each one? i.e. axios.put(‘/api/users/editUser’) and what would that look like?

Hi, @Joe1542. For this example, I’m going to pretend that your site is example.com and the API domain is my.domain.com.

Also, let’s say that when you make the request to https://example.com/api/some/path it should be be redirected to https://my.domain.com/api/some/path. In other words, whatever is after /api/ in both URLs needs to stay the same.

If so, you do not need to make individual rules for each path. You can make a “:splat” or “wildcard” rule to cover all paths like so:

/api/* https://my.domain.com/api/:splat 200

Then, whatever is after the path after /api/ in the original URL will be automatically used in the proxy target URL as well. The “*” will capture the path after /api/ and the “:splat” in the target will reuse whatever path the asterisk captured.

If that doesn’t work or if there are other questions, please let us know.

2 Likes

It works perfectly now, thank you so much for all your help :smiley:

2 Likes