Answer the question
In order to leave comments, you need to log in
How to make a 302 redirect fetch?
There are 3 pages in the react application
1- login (authorization form)
2- confrim (confirmation of sms)
3- some page from the
back when the login form is sent, either json is returned from the back, which says that you need to enter sms and ui shows the confirm page .
If SMS confirmation is disabled, a 302 redirect is returned from the back, by which you need to send the user to the page from this redirect.
The problem is that all requests go through fetch and in it I need to somehow get the url on which to send with a 302 redirect. How to get through to him?
const response = fetch(url, {
method: "POST",
redirect: 'manual',
headers: {
Accept: "applicaton/json",
},
dataType: "JSON",
body: data,
})
.then(res => {
console.log(res.url)
document.location = res.url;
})
Answer the question
In order to leave comments, you need to log in
Finally did this:
const response = fetch(url, {
method: "POST",
headers: {
Accept: "applicaton/json",
},
dataType: "JSON",
body: data,
})
.then(res => {
if (res.redirected) {
document.location = res.url;
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question