redirect issue between builds
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
I have the following code in a page.tsx:
The problem is:
The
export const revalidate = 0
export const dynamic = 'force-dynamic'
const response = await fetch(`<api-url>`, {
method: "GET",
credentials: "include",
headers: headers());
}
if (!response.ok) {
if (response.status == 401) {
console.log("ERROR Unauthorized");
redirect("https://<external-site>")
}
if (response.status == 400) {
console.log("ERROR BadRequest");
redirect("https://<external-site>")
}
if (response.status == 500) {
console.log("ERROR ServerError");
redirect("https://<external-site>")
}
console.log("SERVER ERROR")
}
...
The problem is:
The
console.log
statement was never reached, even in the !response.ok
case, and the redirect always occurs. My hypothesis is that on the first render, the page redirects normally, but then the page is cached and keeps redirecting. I removed the redirects, pushed to my Git repository, and started a new build, but the page is still redirecting. My hypothesis is that the page is still cached and continues redirecting, even after the new build. Are my hypotheses correct? If so, why is this happening even with a new build and also with "revalidate = 0" and "dynamic = 'force-dynamic' "?