diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-06 01:15:14 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-06 01:15:14 +0000 |
| commit | d10b76b54745eb6f4972339caa4219cb1f50ae52 (patch) | |
| tree | 22cf575aeb173c8b100e8adc71620efedec2b3fc /lib | |
| parent | 81531a46c368293b736bb3b12c413cfbe6e00ec4 (diff) | |
| download | karakeep-d10b76b54745eb6f4972339caa4219cb1f50ae52.tar.zst | |
[API] Add the POST /api/v1/links api
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/auth.ts | 25 | ||||
| -rw-r--r-- | lib/prisma.ts | 5 | ||||
| -rw-r--r-- | lib/types/next-auth.d.ts | 12 |
3 files changed, 42 insertions, 0 deletions
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"]; + } +} |
