Skip to content

Commit

Permalink
Merge branch 'main' into mk/fix/smallstuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
matijakljajic authored Dec 31, 2024
2 parents ab26cc7 + fdba7d4 commit c1051ba
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/lib/server/db/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function invalidateExcessSessions(userId: number): Promise<void> {
throw new Error('Invalid userId');
}

const newestSessions = await db
const newestSessions = db
.select({
id: sessionTable.id
})
Expand All @@ -115,11 +115,9 @@ export async function invalidateExcessSessions(userId: number): Promise<void> {
.orderBy(desc(sessionTable.timestamp))
.limit(maxActiveSessions);

const sessionIdsToKeep = newestSessions.map((session) => session.id);

await db
.delete(sessionTable)
.where(and(eq(sessionTable.userId, userId), notInArray(sessionTable.id, sessionIdsToKeep)));
.where(and(eq(sessionTable.userId, userId), notInArray(sessionTable.id, newestSessions)));
}

export type SessionValidationResult =
Expand Down

0 comments on commit c1051ba

Please sign in to comment.