I'm trying to use Astro's middleware functionality to do an Authentication for every page load.
My question is how do you throw an error from the middleware? Let's say the user is unauthorized. What do we do within the middleware function?
Astro provides this snippet on the docs, but nothing about how to handle errors and status codes.
async function auth(_, next) {
console.log("auth request");
const response = await next();
console.log("auth response");
return response;
}
Thanks!