diff --git a/.changeset/hungry-books-jump.md b/.changeset/hungry-books-jump.md new file mode 100644 index 00000000000..dea7a1c4950 --- /dev/null +++ b/.changeset/hungry-books-jump.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/service-utils": patch +--- + +[service-utils] fix auth for cf workers diff --git a/packages/service-utils/src/cf-worker/index.ts b/packages/service-utils/src/cf-worker/index.ts index ea93dd8c33f..f669427c0a4 100644 --- a/packages/service-utils/src/cf-worker/index.ts +++ b/packages/service-utils/src/cf-worker/index.ts @@ -6,7 +6,10 @@ import type { import type { Request } from "@cloudflare/workers-types"; import type { CoreServiceConfig, TeamAndProjectResponse } from "../core/api.js"; import { authorize } from "../core/authorize/index.js"; -import type { AuthorizationInput } from "../core/authorize/index.js"; +import type { + AuthorizationInput, + TeamAndProjectCacheWithPossibleTTL, +} from "../core/authorize/index.js"; import type { AuthorizationResult } from "../core/authorize/types.js"; import type { CoreAuthInput } from "../core/types.js"; @@ -54,14 +57,14 @@ export async function authorizeWorker( return await authorize(authData, serviceConfig, { get: async (clientId: string) => serviceConfig.kvStore.get(clientId), - put: (clientId: string, data: TeamAndProjectResponse) => + put: (clientId: string, teamAndProjectResponse: TeamAndProjectResponse) => serviceConfig.ctx.waitUntil( serviceConfig.kvStore.put( clientId, JSON.stringify({ updatedAt: Date.now(), - data, - }), + teamAndProjectResponse, + } satisfies TeamAndProjectCacheWithPossibleTTL), { expirationTtl: serviceConfig.cacheTtlSeconds && diff --git a/packages/service-utils/src/core/authorize/index.ts b/packages/service-utils/src/core/authorize/index.ts index 9c3210e2569..3e6e5045c9e 100644 --- a/packages/service-utils/src/core/authorize/index.ts +++ b/packages/service-utils/src/core/authorize/index.ts @@ -28,7 +28,7 @@ export type CacheOptions = { cacheTtlSeconds: number; }; -type TeamAndProjectCacheWithPossibleTTL = +export type TeamAndProjectCacheWithPossibleTTL = | { teamAndProjectResponse: TeamAndProjectResponse; updatedAt: number;