File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 11import { base64 } from "@hexagon/base64" ;
22import { getLogger } from "@logtape/logtape" ;
33
4+ import { lt } from "drizzle-orm" ;
45import db , { type Transaction } from "../db" ;
56import * as schema from "../schema" ;
67import type { Uuid } from "../uuid" ;
@@ -10,6 +11,7 @@ const logger = getLogger(["hollo", "oauth"]);
1011const ACCESS_GRANT_SIZE = 64 ;
1112const ACCESS_TOKEN_SIZE = 64 ;
1213const TEN_MINUTES = 10 * 60 * 1000 ;
14+ const ONE_DAY = 3600 * 24 * 1000 ;
1315
1416export 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,
You can’t perform that action at this time.
0 commit comments