Files
buzz-sheet/lib/commission/server.ts
T
gunshiz 0022625edb
CI / Verify (push) Successful in 3m14s
CI / Build immutable images and deploy (push) Successful in 4m0s
feat : big update
2026-10-01 18:37:15 +07:00

31 lines
1.2 KiB
TypeScript

import "server-only";
import { headers } from "next/headers";
import { getAuth } from "@/lib/auth/server";
import { getDb } from "@/db";
import { users } from "@/db/schema";
import { eq } from "drizzle-orm";
import { HttpError } from "@/lib/security/http";
import { getRedisClient, redisEventChannel } from "@/lib/redis/client";
export async function requireCommissionUser() {
const session = await getAuth().api.getSession({ headers: await headers() });
if (!session?.user) throw new HttpError(401, "unauthorized");
const [user] = await getDb().select().from(users).where(eq(users.id, session.user.id)).limit(1);
if (!user || user.banned) throw new HttpError(401, "unauthorized");
return user;
}
export async function notifyCommission(ticketId: string, userId: string) {
try {
const client = await getRedisClient();
await Promise.all([
client.publish(redisEventChannel(`commission:ticket:${ticketId}`), "changed"),
client.publish(redisEventChannel(`commission:user:${userId}`), "changed"),
client.publish(redisEventChannel("commission:admin"), "changed"),
]);
} catch {
// The database is authoritative; a reconnect or page refresh catches up.
}
}