mirror of
https://github.com/arthur-pbty/binouz.git
synced 2026-06-18 05:39:44 +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,38 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const gradeId = body?.gradeId as string | undefined;
|
||||
if (!gradeId) {
|
||||
return Response.json({ error: "Grade id required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const grade = await db.grade.findUnique({ where: { id: gradeId } });
|
||||
if (!grade) {
|
||||
return Response.json({ error: "Grade not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const purchase = await db.purchase.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
gradeId: grade.id,
|
||||
amount: grade.price,
|
||||
status: "PENDING",
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json({
|
||||
id: purchase.id,
|
||||
status: purchase.status,
|
||||
message: "Mock purchase queued",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user