Skip to content

Commit a79ff88

Browse files
committed
Add cleanup of expired access grants
1 parent 946d8f2 commit a79ff88

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/oauth/helpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { base64 } from "@hexagon/base64";
22
import { getLogger } from "@logtape/logtape";
33

4+
import { lt } from "drizzle-orm";
45
import db, { type Transaction } from "../db";
56
import * as schema from "../schema";
67
import type { Uuid } from "../uuid";
@@ -10,6 +11,7 @@ const logger = getLogger(["hollo", "oauth"]);
1011
const ACCESS_GRANT_SIZE = 64;
1112
const ACCESS_TOKEN_SIZE = 64;
1213
const TEN_MINUTES = 10 * 60 * 1000;
14+
const ONE_DAY = 3600 * 24 * 1000;
1315

1416
export type AccessGrant = {
1517
code: string;
@@ -27,6 +29,14 @@ export async function createAccessGrant(
2729
true,
2830
);
2931

32+
try {
33+
await db
34+
.delete(schema.accessGrants)
35+
.where(lt(schema.accessGrants.revoked, new Date(Date.now() - ONE_DAY)));
36+
} catch (err) {
37+
logger.warn("Failed to clean up expired access grants", { err });
38+
}
39+
3040
await db.insert(schema.accessGrants).values({
3141
id: crypto.randomUUID(),
3242
code,

0 commit comments

Comments
 (0)