feat: add share pages comments and server actions

This commit is contained in:
2026-08-16 00:58:46 +07:00 Unverified
parent 5bf5d2a2c0
commit 9617d67c7c
14 changed files with 1157 additions and 108 deletions
+32
View File
@@ -0,0 +1,32 @@
import "server-only";
import { eq } from "drizzle-orm";
import { getServerSession } from "next-auth";
import { db } from "@/db";
import { users } from "@/db/schema";
import { getSessionDiscordId, type SessionWithDiscord } from "@/lib/auth/auth";
import { authOptions } from "@/lib/auth/auth-options";
import { ShareHttpError } from "@/lib/share/http-error";
export async function requireShareAuthor() {
const session = await getServerSession(authOptions);
const discordId = getSessionDiscordId(session);
const userId = (session as SessionWithDiscord | null)?.user?.id;
if (!discordId || !userId) {
throw new ShareHttpError("Unauthorized", 401);
}
const [user] = await db
.select({ id: users.id, name: users.name, image: users.image })
.from(users)
.where(eq(users.id, userId))
.limit(1);
if (!user) throw new ShareHttpError("Unauthorized", 401);
return {
userId: user.id,
discordId,
displayName: user.name || session?.user?.name || "Discord user",
avatarUrl: user.image || session?.user?.image || null,
};
}