Repository navigation
ctx.identityのアクセス可否を型レベルで保証する - #14
Merged
Merged
Conversation
kaito02020424
requested review from
tutinoko2048
and
a lite review from Copilot
September 28, 2026 12:31
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The fallback public typing is incorrect, and several documentation and type-coverage issues remain unresolved.
Review effort: Lite
Findings: 3
Open (3)
What changed in this PR
Adds conditional TypeScript typing for ctx.identity based on verifyClientToken.
Changes:
- Adds conditional identity types.
- Propagates verification state through gateway contexts and events.
- Updates tests and documentation.
| File | Summary and findings |
|---|---|
src/types.ts |
Adds conditional identity types. Moderate (1 vote): the boolean fallback should preserve a required identity property with an undefined union. |
src/gateway.ts |
Propagates verifier state through gateway generics. Nit (2 votes): add compile-time assertions for all IsVerified branches and consumers. |
src/gateway.test.ts |
Tests inaccessible identity without verification. Nit (1 vote): add assertions for verified and uncertain verifier cases. |
README.md |
Documents the new typing behavior. Nits: fix the invalid unverified example (2 votes), preserve verified context typing for rateLimit (2 votes), and add missing imports (1 vote). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| `c.identity` is only available after successful verification. Set `requireClientIdentity: true` if | ||
| every join request must have a verified identity, otherwise requests without one skip this XUID rule: | ||
| XUID instead, use a key function on a gateway with `verifyClientToken`. Every join that reaches it | ||
| has a verified `c.identity`; on a gateway without a verifier, reading it is a type error: |
| rateLimit({ | ||
| windowMs: 60_000, | ||
| rules: [rateLimit.custom<JoinContext>(2, (c) => c.identity?.xuid)], | ||
| rules: [rateLimit.custom(2, (c) => c.identity.xuid)], |
| use(middleware: GatewayMiddleware): this; | ||
| use(selector: 'info', middleware: GatewayMiddleware<ServerInfoContext>): this; | ||
| use(selector: 'join', middleware: GatewayMiddleware<JoinContext>): this; | ||
| use(selector: 'join', middleware: GatewayMiddleware<JoinContext<IsVerified<Options>>>): this; |
| verifyClientToken: VerifyClientToken; | ||
| } | ||
| ? true | ||
| : Options extends { |
Member
There was a problem hiding this comment.
Options extends Omit<NetherNetGatewayOptions, 'verifyClientToken'> & {
verifyClientToken?: undefined;
}にした方が今後NetherNetGatewayOptionsに何か追加したときにここも書き換える必要がなくなりそう?
| constructor(options: NetherNetGatewayOptions) { | ||
| super(); | ||
| this.options = { ...options }; | ||
| this.options = Object.freeze({ |
Member
There was a problem hiding this comment.
ここは手動で列挙せずにスプレッドさせたオブジェクトをfreezeではだめなんですかね?
this.options = Object.freeze({ ...options });
tutinoko2048
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

概要
ctx.identityについて, 型レベルでverifyClientTokenオプションの有無によりアクセス可能性を制御します。verifyClientTokenオプションが設定されている場合,ctx.identity`もctx.untrustedIdentity`もアクセス可能です。verifyClientTokenオプションが設定されていない場合,ctx.identity`はアクセス不可能ですがctx.untrustedIdentity`はアクセス可能です。identity: NetherNetIdentity | undefinedと推論され, 実装側で型の絞り込みを要求します。