catch 401 error in entry server

async function preProcessor(forward: MiddlewareFn, event: FetchEvent, session: Session) {
const response = await forward(event);
console.log("status", response.status);
if (response.status === 401) {
return redirect("/", {
headers: {
"Set-Cookie": await storage.destroySession(session),
},
});
}
return response;
}
async function preProcessor(forward: MiddlewareFn, event: FetchEvent, session: Session) {
const response = await forward(event);
console.log("status", response.status);
if (response.status === 401) {
return redirect("/", {
headers: {
"Set-Cookie": await storage.destroySession(session),
},
});
}
return response;
}
({ forward }) => {
return async (event) => {
const pathname = new URL(event.request.url).pathname;
const isApiPath = pathname.startsWith("/api") || pathname.startsWith("/_m");
const session = await getSession(event.request.headers.get("Cookie"));
if (isApiPath) {
return await preProcessor (forward, event, session);
}
})
({ forward }) => {
return async (event) => {
const pathname = new URL(event.request.url).pathname;
const isApiPath = pathname.startsWith("/api") || pathname.startsWith("/_m");
const session = await getSession(event.request.headers.get("Cookie"));
if (isApiPath) {
return await preProcessor (forward, event, session);
}
})
I am trying to destroy sessions and redirect to sign in page on 401 console.log is logging 401 but it is not either being redirected or the session destroy
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server