-
Hello. routes.get(
"/",
jwt({
secret: config.SECRET_KEY,
}),
async (c) => {
const payload = c.get("jwtPayload"); // any
// ...
}
); In the interface Variables {
jwtPayload: {
sub: string;
};
}
const app = new Hono<{ Variables: Variables }>().basePath("/api");
app.route("/some-route", routes); However, the
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @sz3lbi. interface Variables {
jwtPayload: {
sub: string;
};
}
const routes = new Hono<{ Variables: Variables }>();
routes.get(
"/",
jwt({
secret: config.SECRET_KEY,
}),
async (c) => {
const payload = c.get("jwtPayload"); // probably typed!
// ...
}
);
// ...
const app = new Hono<{ Variables: Variables }>().basePath("/api");
app.route("/some-route", routes); I hope you can resolve this problem. |
Beta Was this translation helpful? Give feedback.
-
There's also a way to have the types of import type { MiddlewareHandler } from "hono";
export interface JwtClaims {
id: number
}
export const jwtAuth = jwt({
secret: process.env.JWT_SECRET,
}) as MiddlewareHandler<{
Variables: { jwtPayload: JwtClaims };
}>; Would be much nicer if the |
Beta Was this translation helpful? Give feedback.
Hi @sz3lbi.
Variables specifications cannot be used in
app.route
.You must specify it when you create your
routes
.I hope you can resolve this problem.