Skip to content

Specify type-safe jwtPayload#49

Closed
CharlesFarris wants to merge 5 commits into
mainfrom
make-jwt-payload-typesafe
Closed

Specify type-safe jwtPayload#49
CharlesFarris wants to merge 5 commits into
mainfrom
make-jwt-payload-typesafe

Conversation

@CharlesFarris

Copy link
Copy Markdown
Contributor
  • Add helper methods
  • Add tests

- Add helper methods
- Add tests
Copilot AI review requested due to automatic review settings May 24, 2026 19:59
@CharlesFarris CharlesFarris self-assigned this May 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a concrete, shared JWT payload shape (TodoJwtPayload) and a helper to create it, then updates page handlers and tests to rely on jwtPayload.preferred_username directly instead of parsing an unknown payload.

Changes:

  • Added TodoJwtPayload and createTodoJwtPayload helper in src/shared/jwtMiddleware.ts with unit tests.
  • Updated authenticated pages and related tests to use c.var.jwtPayload.preferred_username and to sign tokens with the new payload shape.
  • Removed the previous getUsernameFromJwtPayload utility (and its tests) that defensively handled unknown payloads.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/shared/utility.ts Removes the previous JWT payload parsing helper.
src/shared/utility.test.ts Removes tests for the deleted parsing helper.
src/shared/jwtMiddleware.ts Adds TodoJwtPayload type and createTodoJwtPayload helper.
src/shared/jwtMiddleware.test.ts Adds unit tests for createTodoJwtPayload.
src/shared/appVariables.ts Replaces JwtVariables with an explicit jwtPayload: TodoJwtPayload variable.
src/shared/pageJwtMiddleware.test.ts Updates JWT signing in tests to use the new typed payload helper.
src/features/login/loginApi.tsx Introduces a typed jwtPayload object when signing login tokens.
src/features/home/homePage.tsx Uses c.var.jwtPayload.preferred_username directly.
src/features/home/homePage.test.tsx Updates test JWT signing to the new payload helper.
src/features/add-todo/addToDoPage.tsx Uses c.var.jwtPayload.preferred_username directly.
src/features/add-todo/addToDoPage.test.tsx Updates test JWT signing to the new payload helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/features/login/loginApi.tsx Outdated
Comment thread src/features/login/loginApi.tsx Outdated
Comment thread src/shared/appVariables.ts
Comment thread src/features/home/homePage.tsx Outdated
Comment thread src/features/add-todo/addToDoPage.tsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Comment thread src/features/login/loginApi.tsx Outdated
Comment thread src/features/home/homePage.tsx Outdated
Comment on lines +9 to +10
.get("/", (c) => {
const username = getUsernameFromJwtPayload(c.var.jwtPayload);
const username = parseJwtPayload(c.var.jwtPayload).preferred_username;
Comment thread src/features/home/homePage.tsx Outdated
Comment thread src/features/add-todo/addToDoPage.tsx Outdated
Comment on lines +9 to +10
.get("/", (c) => {
const username = getUsernameFromJwtPayload(c.var.jwtPayload);

const username = parseJwtPayload(c.var.jwtPayload).preferred_username;
Comment thread src/features/add-todo/addToDoPage.tsx Outdated
Comment thread src/shared/jwtPayload.ts Outdated
Copilot AI review requested due to automatic review settings May 25, 2026 01:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

logger: Logger;
} & JwtVariables;
jwtPayload: unknown;
validJwtPayload: JwtPayload;
Comment on lines +8 to +13
const jwtPayloadSchema = z.object({
sub: z.string(),
preferred_username: z.string(),
role: z.string(),
iss: z.string(),
exp: z.number(),
Comment on lines 68 to 74
const appConfig = createAppConfig({
JWT_SECRET: "12345678901234567890123456789012",
});
const token = await sign({ sub: "1234" }, appConfig.jwt.secret, "HS256");
const token = await sign(createJwtPayload(), appConfig.jwt.secret, "HS256");
let handlerReached = false;
const app = new Hono<{ Variables: AppVariables }>()
.use("*", createAppConfigMiddleware(appConfig))
@CharlesFarris

Copy link
Copy Markdown
Contributor Author

The branch was abandoned in favor of a different approach.

@CharlesFarris CharlesFarris deleted the make-jwt-payload-typesafe branch May 25, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants