From 159262572aa028331d26adb412e2b64234f10310 Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Tue, 13 Aug 2024 13:03:42 +0200 Subject: [PATCH] Expose the request context for AuthVerifier and StreamAuthVerifier as distinct types --- .changeset/giant-starfishes-fry.md | 5 +++++ packages/xrpc-server/src/types.ts | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .changeset/giant-starfishes-fry.md diff --git a/.changeset/giant-starfishes-fry.md b/.changeset/giant-starfishes-fry.md new file mode 100644 index 00000000000..8f20fdb00cc --- /dev/null +++ b/.changeset/giant-starfishes-fry.md @@ -0,0 +1,5 @@ +--- +"@atproto/xrpc-server": patch +--- + +Expose the request context for AuthVerifier and StreamAuthVerifier as distinct types diff --git a/packages/xrpc-server/src/types.ts b/packages/xrpc-server/src/types.ts index c12c3c35891..db171e9ddea 100644 --- a/packages/xrpc-server/src/types.ts +++ b/packages/xrpc-server/src/types.ts @@ -90,14 +90,22 @@ export type XRPCStreamHandler = (ctx: { export type AuthOutput = HandlerAuth | HandlerError -export type AuthVerifier = (ctx: { +export interface AuthVerifierContext { req: express.Request res: express.Response -}) => Promise | AuthOutput +} + +export type AuthVerifier = ( + ctx: AuthVerifierContext, +) => Promise | AuthOutput -export type StreamAuthVerifier = (ctx: { +export interface StreamAuthVerifierContext { req: IncomingMessage -}) => Promise | AuthOutput +} + +export type StreamAuthVerifier = ( + ctx: StreamAuthVerifierContext, +) => Promise | AuthOutput export type CalcKeyFn = (ctx: XRPCReqContext) => string | null export type CalcPointsFn = (ctx: XRPCReqContext) => number