diff --git a/src/data-access/sessions.ts b/src/data-access/sessions.ts index a161d1e..a21d036 100644 --- a/src/data-access/sessions.ts +++ b/src/data-access/sessions.ts @@ -3,6 +3,6 @@ import { sessions } from "@/db/schema"; import { UserId } from "@/use-cases/types"; import { eq } from "drizzle-orm"; -export async function deleteSessionForUser(userId: UserId) { - await db.delete(sessions).where(eq(sessions.userId, userId)); +export async function deleteSessionForUser(userId: UserId, trx = db) { + await trx.delete(sessions).where(eq(sessions.userId, userId)); } diff --git a/src/use-cases/users.tsx b/src/use-cases/users.tsx index ffb5a8f..c05e366 100644 --- a/src/use-cases/users.tsx +++ b/src/use-cases/users.tsx @@ -38,6 +38,7 @@ import { } from "./errors"; import { db } from "@/db"; import { createTransaction } from "@/data-access/utils"; +import { deleteSessionForUser } from "@/data-access/sessions"; export async function deleteUserUseCase( authenticatedUser: UserSession, @@ -152,6 +153,7 @@ export async function changePasswordUseCase(token: string, password: string) { await createTransaction(async (trx) => { await deletePasswordResetToken(token, trx); await updatePassword(userId, password, trx); + await deleteSessionForUser(userId, trx); }); }