From d10b76b54745eb6f4972339caa4219cb1f50ae52 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 6 Feb 2024 01:15:14 +0000 Subject: [API] Add the POST /api/v1/links api --- lib/auth.ts | 25 +++++++++++++++++++++++++ lib/prisma.ts | 5 +++++ lib/types/next-auth.d.ts | 12 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 lib/auth.ts create mode 100644 lib/prisma.ts create mode 100644 lib/types/next-auth.d.ts (limited to 'lib') diff --git a/lib/auth.ts b/lib/auth.ts new file mode 100644 index 00000000..9b21e605 --- /dev/null +++ b/lib/auth.ts @@ -0,0 +1,25 @@ +import NextAuth, { NextAuthOptions } from "next-auth" +import { PrismaAdapter } from "@next-auth/prisma-adapter" +import AuthentikProvider from "next-auth/providers/authentik"; +import serverConfig from "@/lib/config"; +import prisma from "@/lib/prisma"; + +let providers = []; + +if (serverConfig.auth.authentik) { + providers.push(AuthentikProvider(serverConfig.auth.authentik)); +} + +export const authOptions: NextAuthOptions = { + // Configure one or more authentication providers + adapter: PrismaAdapter(prisma), + providers: providers, + callbacks: { + session({ session, token, user }) { + session.user = { ...user }; + return session; + } + } +}; + +export const authHandler = NextAuth(authOptions); diff --git a/lib/prisma.ts b/lib/prisma.ts new file mode 100644 index 00000000..d73ba5f2 --- /dev/null +++ b/lib/prisma.ts @@ -0,0 +1,5 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient(); + +export default prisma; diff --git a/lib/types/next-auth.d.ts b/lib/types/next-auth.d.ts new file mode 100644 index 00000000..bdd3bd03 --- /dev/null +++ b/lib/types/next-auth.d.ts @@ -0,0 +1,12 @@ +import NextAuth, { DefaultSession } from "next-auth" + +declare module "next-auth" { + /** + * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context + */ + interface Session { + user: { + id: string; + } & DefaultSession["user"]; + } +} -- cgit v1.2.3-70-g09d2