Custom response with bearerAuth

I would like to return a custom response when verifyToken is false.
const authMiddleware = bearerAuth({
verifyToken: async (token, c) => {
const data = await c.env.AUTH.get(token);
if (!data) {
return false; // response: Plz provide valid apiKey
}
if (data.count > data.quota) {
return false; // response: Quota exceeded
}
return true;
},
});
const authMiddleware = bearerAuth({
verifyToken: async (token, c) => {
const data = await c.env.AUTH.get(token);
if (!data) {
return false; // response: Plz provide valid apiKey
}
if (data.count > data.quota) {
return false; // response: Quota exceeded
}
return true;
},
});
Is it possible?
1 Reply
Aditya Mathur
Aditya Mathur5mo ago
Maybe you can throw http exceptions - https://hono.dev/docs/api/exception
Exception - Hono
Ultrafast web framework for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Want results from more Discord servers?
Add your server