import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import dbConnect from '../../../utils/helpers/dbHelpers';
const User = require('../../../models/user');

export default NextAuth({
  session: {
    jwt: true,
  },
  providers: [
    Credentials({
      async authorize(credentials) {
        await dbConnect();

        const user = await User.findByCredentials(
          credentials.username,
          credentials.password
        );
        return { name: user.fullName };
      },
    }),
  ],
});
