flowstate/actions/auth.actions.ts
Chneemann 9802febef3
All checks were successful
Deploy Flowstate to VPS / deploy (push) Successful in 5s
refactor(auth): extract handleSignOut server action into dedicated module to fix client build error
2026-08-22 06:56:07 +02:00

31 lines
802 B
TypeScript

/**
* @file actions/auth.actions.ts
* @description Server actions for handling user logout and status updates.
*/
"use server";
import { auth, signOut } from "@/auth";
import { db } from "@/db";
import { usersTable } from "@/db/schema";
import { eq } from "drizzle-orm";
/**
* Handles user sign-out by updating the user's online status to offline in the database
* and terminating the active session, redirecting to the homepage.
*
* @async
* @returns {Promise<void>} Resolves when the user is signed out and redirected.
*/
export async function handleSignOut() {
const session = await auth();
if (session?.user?.id) {
await db
.update(usersTable)
.set({ isOnline: false })
.where(eq(usersTable.id, session.user.id));
}
await signOut({ redirectTo: "/" });
}