feat: add share pages comments and server actions
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user