fix(registry): 为 Hono Context 声明 AuthVariables 类型,消除 genes API 的 Type…#19
Conversation
…Script 报错 Made-with: Cursor
There was a problem hiding this comment.
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
AuthVariablestype from the auth middleware module - Applied
Hono<{ Variables: AuthVariables }>to the main app andgenesRouter - 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 }>(); |
There was a problem hiding this comment.
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()— usesc.get('authRole')(line 12) andc.get('publisherId')(line 116)templates.ts:templatesRouter = new Hono()— usesc.get('authRole')(line 12) andc.get('publisherId')(line 109)keys.ts:keysRouter = new Hono()— usesc.get('publisherId')(lines 16, 39, 57)reviews.ts:reviewsRouter = new Hono()— usesc.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.
Made-with: Cursor
Made-with: Cursor
…Script 报错
Made-with: Cursor