Skip to content

JWT middleware typed payload #3168

Answered by nakasyou
sz3lbi asked this question in Q&A
Jul 20, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @sz3lbi.
Variables specifications cannot be used in app.route.
You must specify it when you create your routes.

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sz3lbi
Comment options

Answer selected by sz3lbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants