From 2ab5d1ec486ee580d11655f9c3219d84b2e997eb Mon Sep 17 00:00:00 2001 From: Kunal Gupta <39487888+iamKunalGupta@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:50:28 +0530 Subject: [PATCH] fix(ui): move authOptions to a separate file --- ui/app/api/auth/[...nextauth]/route.ts | 39 ++------------------------ ui/app/auth/options.ts | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 ui/app/auth/options.ts diff --git a/ui/app/api/auth/[...nextauth]/route.ts b/ui/app/api/auth/[...nextauth]/route.ts index 6f5ef8a9d9..0382c1fb82 100644 --- a/ui/app/api/auth/[...nextauth]/route.ts +++ b/ui/app/api/auth/[...nextauth]/route.ts @@ -1,40 +1,5 @@ -import NextAuth, { AuthOptions } from 'next-auth'; -import { Configuration } from '@/app/config/config'; -import { Provider } from 'next-auth/providers/index'; -import CredentialsProvider from 'next-auth/providers/credentials'; - - -function getEnabledProviders(): Provider[] { - return [ - CredentialsProvider({ - name: 'Password', - credentials: { - password: { label: "Password", type: "password" } - }, - async authorize(credentials, req) { - if (credentials == null || credentials.password != Configuration.authentication.PEERDB_PASSWORD) { - return null - } - return { id: '1', name: 'Admin'}; - } - }) - ] -} - -export const authOptions: AuthOptions = { - providers: getEnabledProviders(), - debug: false, - session: { - strategy: 'jwt', - maxAge: 60 * 60, // 1h - }, - // adapter: PrismaAdapter(prisma), - secret: Configuration.authentication.NEXTAUTH_SECRET, - theme: { - colorScheme: 'light', - logo: '/images/peerdb-combinedMark.svg', - }, -}; +import NextAuth from 'next-auth'; +import { authOptions } from '@/app/auth/options'; const handler = NextAuth(authOptions); diff --git a/ui/app/auth/options.ts b/ui/app/auth/options.ts new file mode 100644 index 0000000000..8aaea2349d --- /dev/null +++ b/ui/app/auth/options.ts @@ -0,0 +1,36 @@ +import { Provider } from 'next-auth/providers/index'; +import CredentialsProvider from 'next-auth/providers/credentials'; +import { Configuration } from '@/app/config/config'; +import { AuthOptions } from 'next-auth'; + +function getEnabledProviders(): Provider[] { + return [ + CredentialsProvider({ + name: 'Password', + credentials: { + password: { label: 'Password', type: 'password' }, + }, + async authorize(credentials, req) { + if (credentials == null || credentials.password != Configuration.authentication.PEERDB_PASSWORD) { + return null; + } + return { id: '1', name: 'Admin' }; + }, + }), + ]; +} + +export const authOptions: AuthOptions = { + providers: getEnabledProviders(), + debug: false, + session: { + strategy: 'jwt', + maxAge: 60 * 60, // 1h + }, + // adapter: PrismaAdapter(prisma), + secret: Configuration.authentication.NEXTAUTH_SECRET, + theme: { + colorScheme: 'light', + logo: '/images/peerdb-combinedMark.svg', + }, +};