Skip to content

Commit

Permalink
fix(ui): move authOptions to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKunalGupta committed Jan 8, 2024
1 parent 998c660 commit 2ab5d1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
39 changes: 2 additions & 37 deletions ui/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
36 changes: 36 additions & 0 deletions ui/app/auth/options.ts
Original file line number Diff line number Diff line change
@@ -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',
},
};

0 comments on commit 2ab5d1e

Please sign in to comment.