diff --git a/prisma/migrations/20250428111616_giveaway_update3/migration.sql b/prisma/migrations/20250428111616_giveaway_update3/migration.sql
new file mode 100644
index 0000000..b78cd53
--- /dev/null
+++ b/prisma/migrations/20250428111616_giveaway_update3/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "Giveaway" ADD COLUMN "duration" INTEGER,
+ADD COLUMN "endsAt" TIMESTAMP(3);
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index b727e97..6523268 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -64,6 +64,8 @@ model Giveaway {
prize String
active Boolean @default(true)
createdAt DateTime @default(now())
+ duration Int?
+ endsAt DateTime?
entryCost Int @default(7000000)
entries Entry[]
}
diff --git a/src/app/admin/AdminClient.tsx b/src/app/admin/AdminClient.tsx
index 5f5e164..c909774 100644
--- a/src/app/admin/AdminClient.tsx
+++ b/src/app/admin/AdminClient.tsx
@@ -7,7 +7,7 @@ interface AdminClientProps {
}
export default function AdminClient({ email }: AdminClientProps) {
- const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "" });
+ const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 });
const [userCoins, setUserCoins] = useState({ userId: "", coins: 0 });
const handleCreateGiveaway = async () => {
@@ -18,7 +18,7 @@ export default function AdminClient({ email }: AdminClientProps) {
});
if (response.ok) {
alert("Giveaway created successfully!");
- setGiveaway({ title: "", description: "", value:0, prize: "" }); // Reset form
+ setGiveaway({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 }); // Reset form
} else {
const error = await response.json();
alert(`Failed to create giveaway: ${error.error}`);
@@ -50,37 +50,44 @@ export default function AdminClient({ email }: AdminClientProps) {
Create Giveaway
setGiveaway({ ...giveaway, title: e.target.value })}
- className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
+ type="text"
+ placeholder="Title"
+ value={giveaway.title}
+ onChange={(e) => setGiveaway({ ...giveaway, title: e.target.value })}
+ className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
/>
diff --git a/src/app/api/admin/create-giveaway/route.ts b/src/app/api/admin/create-giveaway/route.ts
index 5a960f0..39d5299 100644
--- a/src/app/api/admin/create-giveaway/route.ts
+++ b/src/app/api/admin/create-giveaway/route.ts
@@ -3,7 +3,7 @@ import { db } from "@/lib/db";
export async function POST(req: Request) {
const body = await req.json();
- const { title, description, value, prize } = body;
+ const { title, description, value, prize, duration, endsAt } = body;
if (!title || !description || !prize || !value) {
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
@@ -16,6 +16,8 @@ export async function POST(req: Request) {
description,
prize,
value,
+ duration,
+ endsAt: new Date(endsAt),
},
});
return NextResponse.json(giveaway);
diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts
index d64c7ec..1edf662 100644
--- a/src/app/api/auth/[...nextauth]/route.ts
+++ b/src/app/api/auth/[...nextauth]/route.ts
@@ -2,6 +2,7 @@ import NextAuth, { SessionStrategy } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { db } from "@/lib/db"; // Ensure this is the correct path to your Prisma client
+import axios from "axios";
if (!db) {
throw new Error("Prisma client is not initialized. Check your database configuration.");
@@ -13,6 +14,11 @@ export const authOptions = {
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
+ authorization: {
+ params: {
+ scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
+ },
+ },
}),
],
secret: process.env.NEXTAUTH_SECRET,
diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx
index fca94da..3f647c1 100644
--- a/src/app/profile/page.tsx
+++ b/src/app/profile/page.tsx
@@ -12,6 +12,11 @@ export default async function ProfilePage() {
const user = await db.user.findUnique({
where: { email: session.user?.email! },
+ select: {
+ name: true,
+ email: true,
+ coins: true,
+ },
});
if (!user) {