mirror of
https://github.com/arthur-pbty/binouz.git
synced 2026-06-10 19:04:13 +02:00
feat: add authentication and user management features
- Implemented AuthButton component for Discord sign-in and sign-out functionality. - Created CopyButton component for copying server IP addresses. - Developed EventCard and GradeCard components for displaying events and grades. - Added Footer and Navbar components for site navigation and information. - Introduced PurchaseButton for handling grade purchases with Stripe integration. - Created SectionHeader component for consistent section titles. - Implemented session management with SessionProvider for NextAuth. - Set up PostgreSQL database with Docker and Prisma for data management. - Added admin guard functionality to restrict access to certain routes. - Configured NextAuth with Discord provider for user authentication. - Defined Prisma schema for user, admin, grade, event, and purchase models. - Seeded database with initial grades and events data. - Added SVG hero image for the landing page. - Extended NextAuth types to include additional user properties.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import type { NextRequest } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/admin";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const guard = await requireAdmin();
|
||||
if (!guard.ok) return guard.response;
|
||||
|
||||
const { id } = await params;
|
||||
await db.admin.delete({ where: { id } });
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { db } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/admin";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type AdminWithUser = {
|
||||
id: string;
|
||||
discordId: string;
|
||||
user: {
|
||||
name?: string | null;
|
||||
email?: string | null;
|
||||
discordUsername?: string | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
const guard = await requireAdmin();
|
||||
if (!guard.ok) return guard.response;
|
||||
|
||||
const admins = await db.admin.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: { user: true },
|
||||
});
|
||||
|
||||
const adminUsers = admins as AdminWithUser[];
|
||||
|
||||
return Response.json(
|
||||
adminUsers.map((admin) => ({
|
||||
id: admin.id,
|
||||
discordId: admin.discordId,
|
||||
user: admin.user
|
||||
? {
|
||||
name: admin.user.name,
|
||||
email: admin.user.email,
|
||||
discordUsername: admin.user.discordUsername,
|
||||
}
|
||||
: null,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const guard = await requireAdmin();
|
||||
if (!guard.ok) return guard.response;
|
||||
|
||||
const body = await request.json();
|
||||
const discordId = body?.discordId?.toString().trim();
|
||||
|
||||
if (!discordId) {
|
||||
return Response.json({ error: "Discord ID required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const user = await db.user.findUnique({ where: { discordId } });
|
||||
if (!user) {
|
||||
return Response.json({ error: "User not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const admin = await db.admin.upsert({
|
||||
where: { discordId },
|
||||
update: {},
|
||||
create: { discordId, userId: user.id },
|
||||
});
|
||||
|
||||
return Response.json({
|
||||
id: admin.id,
|
||||
discordId: admin.discordId,
|
||||
user: {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
discordUsername: user.discordUsername,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user