diff --git a/app/(payment)/pay/page.tsx b/app/(payment)/pay/page.tsx new file mode 100644 index 0000000..3652ef0 --- /dev/null +++ b/app/(payment)/pay/page.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +function page() { + return ( +
page
+ ) +} + +export default page \ No newline at end of file diff --git a/app/account/page.tsx b/app/account/page.tsx index 393a3c0..e41dc5d 100644 --- a/app/account/page.tsx +++ b/app/account/page.tsx @@ -1,19 +1,45 @@ -import { DarkModeToggle} from "@/components/ThemeToggle"; +import { DarkModeToggle } from "@/components/ThemeToggle"; import SignOutButton from "@/components/signOutButton"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import React from "react"; -import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server"; +import Image from "next/image"; +import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server"; +import { Label } from "@/components/ui/label"; +import { db } from "@/lib/db"; +import { Lightbulb } from "lucide-react"; export default async function account() { - const {getUser} = getKindeServerSession(); + const { getUser } = getKindeServerSession(); const user = await getUser(); + const dbUser = await db.user.findFirst({ + where: { + id: user.id as string, + }, +}) + +if (!dbUser) { + // create user in db + await db.user.create({ + data: { + id: user.id as string, + email: user.email as string, + }, + }) +} return (
{user ? (
Hi {user.given_name} + Profile Image
) : (
You are not Logged In
@@ -27,6 +53,11 @@ export default async function account() {
+
+
+ Balance: {dbUser?.balance} +
+
) : (
@@ -37,4 +68,4 @@ export default async function account() { )}
); -} \ No newline at end of file +} diff --git a/app/api/auth/[kindeAuth]/route.js b/app/api/auth/[kindeAuth]/route.js deleted file mode 100644 index 7db2fbe..0000000 --- a/app/api/auth/[kindeAuth]/route.js +++ /dev/null @@ -1,6 +0,0 @@ -import {handleAuth} from "@kinde-oss/kinde-auth-nextjs/server"; - -export async function GET(request, {params}) { - const endpoint = params.kindeAuth; - return handleAuth(request, endpoint); -} \ No newline at end of file diff --git a/app/api/auth/[kindeAuth]/route.ts b/app/api/auth/[kindeAuth]/route.ts new file mode 100644 index 0000000..411d0b6 --- /dev/null +++ b/app/api/auth/[kindeAuth]/route.ts @@ -0,0 +1,10 @@ +import { handleAuth } from '@kinde-oss/kinde-auth-nextjs/server' +import { NextRequest } from 'next/server' + +export async function GET( + request: NextRequest, + { params }: any +) { + const endpoint = params.kindeAuth + return handleAuth(request, endpoint) +} \ No newline at end of file diff --git a/app/api/shopping/balance/route.ts b/app/api/shopping/balance/route.ts new file mode 100644 index 0000000..8181964 --- /dev/null +++ b/app/api/shopping/balance/route.ts @@ -0,0 +1,32 @@ +import {NextResponse} from "next/server"; +import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server"; +import { db } from "@/lib/db"; + +export async function GET() { + const {getUser, isAuthenticated} = getKindeServerSession(); + + if (await !isAuthenticated()) { + return new Response("Unauthorized", {status: 401}); + } + const user = await getUser(); + const dbUser = await db.user.findFirst({ + where: { + id: user.id as string, + }, + }) + + if (!dbUser) { + // create user in db + const dbUser = await db.user.create({ + data: { + id: user.id as string, + email: user.email as string, + }, + }) + } + + + const data = {message: "Hello User", id: user.id, balance: dbUser?.balance}; + + return NextResponse.json({data}); +} \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index f6db098..2d0c417 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -30,7 +30,7 @@ export default async function RootLayout({ defaultTheme="light" disableTransitionOnChange > -
{children}
+
{children}