Hello, I am trying to prevent unauthenticated users from running actions on a per-function basis. For that, I would like to send a 403 error code if the user is unauthenticated, but I am not sure how to do that.
Here is what my code looks like:
export const myFunc = server$(async function () {
try {
// Throws an error if the user is not logged-in
const session = requireLogin(this);
// server-side stuff
} catch (error) {
// How to send 403 here?
}
});
I know that I could use middlewares, but if I understand correctly, they are set on a per-route basis, which is not granular enough for me. I am open to discussing it though.
Thank you!