Skip to content

Commit

Permalink
[service-utils] fix auth cache for cf workers (#6219)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Feb 10, 2025
1 parent c86e13b commit 91b0367
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-books-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/service-utils": patch
---

[service-utils] fix auth for cf workers
11 changes: 7 additions & 4 deletions packages/service-utils/src/cf-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion packages/service-utils/src/core/authorize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type CacheOptions = {
cacheTtlSeconds: number;
};

type TeamAndProjectCacheWithPossibleTTL =
export type TeamAndProjectCacheWithPossibleTTL =
| {
teamAndProjectResponse: TeamAndProjectResponse;
updatedAt: number;
Expand Down

0 comments on commit 91b0367

Please sign in to comment.