diff options
author | Linnnus <[email protected]> | 2025-02-18 18:02:23 +0100 |
---|---|---|
committer | Linnnus <[email protected]> | 2025-02-18 18:02:23 +0100 |
commit | e0f5c70f85456297ff9b235c6aeab9746a054f6c (patch) | |
tree | b318241656cde2df9a0f475d0f824f80326b4083 | |
parent | d60f89487ab3bc2390054efcd5d986a4aadd4291 (diff) |
Use abstract client interface for DB interactions
-rw-r--r-- | app/src/lib/server/sessions.ts | 8 | ||||
-rw-r--r-- | app/src/lib/server/users.ts | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/app/src/lib/server/sessions.ts b/app/src/lib/server/sessions.ts index 1b829ff..0ca46e0 100644 --- a/app/src/lib/server/sessions.ts +++ b/app/src/lib/server/sessions.ts @@ -51,7 +51,7 @@ function encodeBase32LowerCaseNoPadding(input: Uint8Array): string { const VALID_MILLISECONDS = 1000 * 60 * 60 * 24 * 30; /** Creates a new session for the user with the given `userId`. */ -export async function createSession(dbConn: pg.PoolClient, userId: number): Promise<Session> { +export async function createSession(dbConn: pg.ClientBase, userId: number): Promise<Session> { const token = generateSessionToken(); const session: Session = { token: token, @@ -78,7 +78,7 @@ export async function createSession(dbConn: pg.PoolClient, userId: number): Prom * @returns A session + user pair if the session is valid, or `null` for both otherwise. */ export async function validateSessionToken( - dbConn: pg.PoolClient, + dbConn: pg.ClientBase, token: string, ): Promise<SessionValidationResult> { // Step 1 @@ -129,13 +129,13 @@ export async function validateSessionToken( /** Invalidates the session with token `sessionToken`. */ export async function invalidateSession( - dbConn: pg.PoolClient, + dbConn: pg.ClientBase, sessionToken: string, ): Promise<void> { await dbConn.query("DELETE sessions WHERE token = ?;", [sessionToken]); } /** Invalidates all sessions for the user with the id `userId`. */ -export async function invalidateAllSessions(dbConn: pg.PoolClient, userId: number): Promise<void> { +export async function invalidateAllSessions(dbConn: pg.ClientBase, userId: number): Promise<void> { await dbConn.query("DELETE sessions WHERE user_id = ?", [userId]); } diff --git a/app/src/lib/server/users.ts b/app/src/lib/server/users.ts index c233fda..a2e734f 100644 --- a/app/src/lib/server/users.ts +++ b/app/src/lib/server/users.ts @@ -17,7 +17,7 @@ export interface User { * @returns The user, or `undefined` on authentication failure. */ export async function getUser( - dbConn: pg.PoolClient, + dbConn: pg.ClientBase, email: string, password: string, ): Promise<User | undefined> { |