Middlewares
Course: Serverless Backends - chapter 11
Creating a simple auth middleware
Section titled “Creating a simple auth middleware”import { Hono, Next } from 'hono'import { Context } from 'hono/jsx';
const app = new Hono()
app.use(async (c, next) => { if (c.req.header("Authorization")) { // Do validation await next() } else { return c.text("You dont have acces"); }})
app.get('/', async (c) => { const body = await c.req.parseBody() console.log(body); console.log(c.req.header("Authorization")); console.log(c.req.query("param"));
return c.json({msg: "as"})})
export default app💡 Notice you have to return the
c.textvalue