aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/api/auth/[...nextauth]/route.tsx22
-rw-r--r--app/api/v1/links/route.ts28
2 files changed, 30 insertions, 20 deletions
diff --git a/app/api/auth/[...nextauth]/route.tsx b/app/api/auth/[...nextauth]/route.tsx
index b9decb30..bfcda516 100644
--- a/app/api/auth/[...nextauth]/route.tsx
+++ b/app/api/auth/[...nextauth]/route.tsx
@@ -1,21 +1,3 @@
-import NextAuth from "next-auth"
-import { PrismaAdapter } from "@next-auth/prisma-adapter"
-import AuthentikProvider from "next-auth/providers/authentik";
-import { PrismaClient } from "@prisma/client"
-import serverConfig from "@/lib/config";
+import { authHandler } from "@/lib/auth";
-const prisma = new PrismaClient()
-
-let providers = [];
-
-if (serverConfig.auth.authentik) {
- providers.push(AuthentikProvider(serverConfig.auth.authentik));
-}
-
-const handler = NextAuth({
- // Configure one or more authentication providers
- adapter: PrismaAdapter(prisma),
- providers: providers,
-});
-
-export { handler as GET, handler as POST }
+export { authHandler as GET, authHandler as POST }
diff --git a/app/api/v1/links/route.ts b/app/api/v1/links/route.ts
new file mode 100644
index 00000000..9103830b
--- /dev/null
+++ b/app/api/v1/links/route.ts
@@ -0,0 +1,28 @@
+import { authOptions } from "@/lib/auth";
+import prisma from "@/lib/prisma";
+import { getServerSession } from "next-auth";
+import { NextRequest, NextResponse } from "next/server";
+
+interface NewLinkRequest {
+ url: string,
+}
+
+export async function POST(request: NextRequest) {
+ // TODO: We probably should be using an API key here instead of the session;
+ const session = await getServerSession(authOptions);
+ if (!session) {
+ return new Response(null, { status: 401 });
+ }
+
+ // TODO: We need proper type assertion here
+ const body: NewLinkRequest = await request.json();
+
+ const link = await prisma.bookmarkedLink.create({
+ data: {
+ url: body.url,
+ userId: session.user.id,
+ }
+ })
+
+ return NextResponse.json(link, { status: 201 });
+}