import NextAuth, { NextAuthOptions } from 'next-auth'; import CredentialsProvider from 'next-auth/providers/credentials'; import bcrypt from 'bcrypt'; import { fetchUser } from '../../../lib/data'; import { User } from '@/app/lib/definitions'; const authOptions: NextAuthOptions = { providers: [ CredentialsProvider({ name: 'credentials', credentials: {}, // TODO: Not sure how to type authorize function correctly // @ts-ignore async authorize(credentials: { email: string; password: string; }): Promise { const { email, password } = credentials; try { const user = await fetchUser(email); if (!user) { return null; } const passwordsMatch = await bcrypt.compare(password, user.password); if (!passwordsMatch) { console.log('Passwords do not match'); return null; } return user; } catch (error) { console.log('Error: ', error); } }, }), ], session: { strategy: 'jwt', }, secret: process.env.NEXTAUTH_SECRET, pages: { signIn: '/login', }, }; const handler = NextAuth(authOptions); export { handler as GET, handler as POST, authOptions };