Skip to content

fix(registry): 为 Hono Context 声明 AuthVariables 类型,消除 genes API 的 Type…#19

Merged
chenchenchenchencj merged 4 commits into
masterfrom
cccc
Mar 9, 2026
Merged

fix(registry): 为 Hono Context 声明 AuthVariables 类型,消除 genes API 的 Type…#19
chenchenchenchencj merged 4 commits into
masterfrom
cccc

Conversation

@chenchenchenchencj

Copy link
Copy Markdown
Collaborator

…Script 报错

Made-with: Cursor

Copilot AI review requested due to automatic review settings March 9, 2026 02:46

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes TypeScript type errors in the GeneHub registry by declaring an AuthVariables type for Hono context variables injected by the auth middleware (authRole, publisherId, githubLogin). The type is applied to the main app and the genesRouter so that c.get('authRole') etc. are recognized by TypeScript.

Changes:

  • Added and exported AuthVariables type from the auth middleware module
  • Applied Hono<{ Variables: AuthVariables }> to the main app and genesRouter
  • Added a PR documentation file explaining the fix

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/registry/src/middleware/auth.ts Exports new AuthVariables type with optional authRole, publisherId, and githubLogin fields
packages/registry/src/app.ts Uses AuthVariables as generic type parameter when creating the Hono app
packages/registry/src/api/genes.ts Uses AuthVariables as generic type parameter when creating genesRouter
docs/pr-registry-context-types.md Documents the PR's purpose, changes, impact, and test plan

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

import * as geneService from '../services/gene-service.js';

export const genesRouter = new Hono();
export const genesRouter = new Hono<{ Variables: AuthVariables }>();

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

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

The same TypeScript error that this PR fixes for genesRouter also exists in other routers that call c.get('authRole') or c.get('publisherId') without declaring AuthVariables:

  • genomes.ts: genomesRouter = new Hono() — uses c.get('authRole') (line 12) and c.get('publisherId') (line 116)
  • templates.ts: templatesRouter = new Hono() — uses c.get('authRole') (line 12) and c.get('publisherId') (line 109)
  • keys.ts: keysRouter = new Hono() — uses c.get('publisherId') (lines 16, 39, 57)
  • reviews.ts: reviewsRouter = new Hono() — uses c.get('publisherId') (line 58)

These routers should also be updated to new Hono<{ Variables: AuthVariables }>() for consistency and to eliminate the same TypeScript errors. In Hono, child routers mounted via app.route() do not inherit the parent's generic type parameters.

Copilot uses AI. Check for mistakes.
Comment thread docs/pr-registry-context-types.md
@chenchenchenchencj chenchenchenchencj self-assigned this Mar 9, 2026
@chenchenchenchencj chenchenchenchencj merged commit 3ef802f into master Mar 9, 2026
2 checks passed
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.

3 participants