From cdceb1bc87dc2d5ef42a7f172ea5dc2263c5c526 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Wed, 21 Feb 2024 16:11:35 -0700 Subject: initialised monorepo with auth and extension communication --- apps/web/src/app/api/auth/[...nextauth]/route.ts | 7 +++++++ apps/web/src/app/api/store/route.ts | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 apps/web/src/app/api/auth/[...nextauth]/route.ts create mode 100644 apps/web/src/app/api/store/route.ts (limited to 'apps/web/src/app/api') diff --git a/apps/web/src/app/api/auth/[...nextauth]/route.ts b/apps/web/src/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 00000000..1570f886 --- /dev/null +++ b/apps/web/src/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,7 @@ +import NextAuth from "next-auth"; + +import { authOptions } from "@/server/auth"; + +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +const handler = NextAuth(authOptions); +export { handler as GET, handler as POST }; diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts new file mode 100644 index 00000000..5c7e76d5 --- /dev/null +++ b/apps/web/src/app/api/store/route.ts @@ -0,0 +1,21 @@ +import { db } from "@/server/db"; +import { eq } from "drizzle-orm"; +import { sessions, users } from "@/server/db/schema"; +import { type NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest) { + try { + const token = req.cookies.get("next-auth.session-token")?.value ?? req.headers.get("Authorization")?.replace("Bearer ", ""); + + const session = await db.select().from(sessions).where(eq(sessions.sessionToken, token!)) + .leftJoin(users, eq(sessions.userId, users.id)) + + if (!session || session.length === 0) { + return NextResponse.json({ message: "Invalid Key, session not found." }, { status: 404 }); + } + + return NextResponse.json({ message: "OK", data: session[0] }, { status: 200 }); + } catch (error) { + return NextResponse.json({ message: "Error", error }, { status: 500 }); + } +} \ No newline at end of file -- cgit v1.2.3