+3
-3
netlify/functions/infrastructure/database/DatabaseService.ts
+3
-3
netlify/functions/infrastructure/database/DatabaseService.ts
···
200
200
async cleanupExpiredSessions(): Promise<void> {
201
201
try {
202
202
const statesDeleted = await this
203
-
.sql`DELETE FROM oauth_states WHERE expires_at < NOW()`;
203
+
.sql`DELETE FROM oauth_states WHERE expires_at < ${new Date().toISOString()}`;
204
204
const sessionsDeleted = await this
205
-
.sql`DELETE FROM oauth_sessions WHERE expires_at < NOW()`;
205
+
.sql`DELETE FROM oauth_sessions WHERE expires_at < ${new Date().toISOString()}`;
206
206
const userSessionsDeleted = await this
207
-
.sql`DELETE FROM user_sessions WHERE expires_at < NOW()`;
207
+
.sql`DELETE FROM user_sessions WHERE expires_at < ${new Date().toISOString()}`;
208
208
209
209
console.log("🧹 Cleanup:", {
210
210
states: (statesDeleted as any).length,
+1
-1
netlify/functions/infrastructure/oauth/stores/SessionStore.ts
+1
-1
netlify/functions/infrastructure/oauth/stores/SessionStore.ts
···
14
14
async get(key: string): Promise<SessionData | undefined> {
15
15
const result = await this.sql`
16
16
SELECT data FROM oauth_sessions
17
-
WHERE key = ${key} AND expires_at > NOW()
17
+
WHERE key = ${key} AND expires_at > ${new Date().toISOString()}
18
18
`;
19
19
const rows = result as OAuthSessionRow[];
20
20
+1
-1
netlify/functions/infrastructure/oauth/stores/StateStore.ts
+1
-1
netlify/functions/infrastructure/oauth/stores/StateStore.ts
···
8
8
async get(key: string): Promise<StateData | undefined> {
9
9
const result = await this.sql`
10
10
SELECT data FROM oauth_states
11
-
WHERE key = ${key} AND expires_at > NOW()
11
+
WHERE key = ${key} AND expires_at > ${new Date().toISOString()}
12
12
`;
13
13
const rows = result as OAuthStateRow[];
14
14
+29
-8
netlify/functions/infrastructure/oauth/stores/UserSessionStore.ts
+29
-8
netlify/functions/infrastructure/oauth/stores/UserSessionStore.ts
···
6
6
private sql = getDbClient();
7
7
8
8
async get(sessionId: string): Promise<UserSessionData | undefined> {
9
-
const result = await this.sql`
10
-
SELECT did, fingerprint FROM user_sessions
11
-
WHERE session_id = ${sessionId} AND expires_at > NOW()
12
-
`;
13
-
const rows = result as UserSessionRow[];
14
-
return rows[0]
15
-
? { did: rows[0].did, fingerprint: rows[0].fingerprint }
16
-
: undefined;
9
+
const fetchSession = async () => {
10
+
const result = await this.sql`
11
+
SELECT did FROM user_sessions
12
+
WHERE session_id = ${sessionId} AND expires_at > ${new Date().toISOString()}
13
+
`;
14
+
const rows = result as UserSessionRow[];
15
+
return rows[0] ? { did: rows[0].did } : undefined;
16
+
};
17
+
18
+
// Try once, if not found retry twice with small delays
19
+
let session = await fetchSession();
20
+
21
+
if (!session) {
22
+
console.log(
23
+
`[UserSessionStore] Session ${sessionId} not found, retrying...`,
24
+
);
25
+
await new Promise((resolve) => setTimeout(resolve, 100));
26
+
session = await fetchSession();
27
+
}
28
+
29
+
if (!session) {
30
+
console.log(
31
+
`[UserSessionStore] Session ${sessionId} still not found, final retry...`,
32
+
);
33
+
await new Promise((resolve) => setTimeout(resolve, 300));
34
+
session = await fetchSession();
35
+
}
36
+
37
+
return session;
17
38
}
18
39
19
40
async set(sessionId: string, data: UserSessionData): Promise<void> {
+1
-1
netlify/functions/oauth-callback.ts
+1
-1
netlify/functions/oauth-callback.ts
···
12
12
const isDev = config.clientType === "loopback";
13
13
14
14
let currentUrl = isDev
15
-
? "http://127.0.0.1:8888"
15
+
? config.redirectUri.replace("/.netlify/functions/oauth-callback", "")
16
16
: config.redirectUri.replace("/.netlify/functions/oauth-callback", "");
17
17
18
18
const params = new URLSearchParams(event.rawUrl.split("?")[1] || "");