0

I have an app which can authorize user through Google provider, and we have api endpoint, to the address of which you need to make a GET request. API answers with 307 code and redirect url, but instead of a redirect, I get a request from the current page:

enter image description here

When i tried to google similar problem, all the answers be like: 'just handle redirect in response', but app call redirect url as GET request from current page immediately, so i can't read response and had error.

I want to achieve the following flow:

  1. User makes a get request to our api
  2. Upon receiving a 307 code, we get just get redirect url, and manualy redirect user from the current page to the page from the response.

I tried to achieve this with Fetch API and Axios

A.Burdonskaya
  • 511
  • 1
  • 4
  • 27
  • Do you understand your CORS error? Do you know what a cross-origin request is and why it's complaining about it? Also, an axios request that encounters a redirect will complete the request with the body of the redirected URL, it will not **navigate** the user to a different page. You'll have to achieve redirection in response to a fetch differently. fetch != navigation – Wyck May 19 '22 at 15:08
  • 1
    @Wyck thank you for the explanation, now it seems clear to me. Do I understand correctly, if i want to achieve flow like from question, i need to get redirect url with 200 status code from api, and then redirect user manualy? – A.Burdonskaya May 19 '22 at 15:13
  • @A.Burdonskaya yes. Client-side, upon getting 307, read the return url and redirect manually. – Ergis May 19 '22 at 15:37
  • @Ergis ok, now my question is: how i can get redirect url from 307 response? If i used `redirect: 'manual'` i can view response from GET request, but i can't get `Location` header – A.Burdonskaya May 19 '22 at 16:03
  • 1
    Unfortunately it's not possible to read information from redirects. I've tried., – Evert May 19 '22 at 17:30
  • May I suggest the approach given in [How to manage a redirect request after a jQuery Ajax call](https://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call) which is to return a 200 success with a JSON payload that describes the URL, and then have JavaScript initiate a `window.location.href=data.redirect` navigation to the new page. – Wyck May 19 '22 at 17:44

0 Answers0