{"size": 1031, "ext": "js", "max_stars_repo_path": "pages/api/auth/[...nextauth].js", "max_stars_repo_name": "vutia/Hotflix", "max_stars_repo_stars_event_min_datetime": "2021-05-25T08:51:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T18:23:20.000Z", "max_issues_repo_path": "pages/api/auth/[...nextauth].js", "max_issues_repo_name": "vutia/Hotflix", "max_issues_repo_issues_event_min_datetime": "2021-07-08T18:15:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-18T15:05:27.000Z", "max_forks_repo_path": "pages/api/auth/[...nextauth].js", "max_forks_repo_name": "vutia/Hotflix", "max_forks_repo_forks_event_min_datetime": "2021-05-27T08:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T08:51:28.000Z"}
{"max_stars_count": 122, "max_issues_count": 3, "max_forks_count": 24, "avg_line_length": 26.4358974359, "max_line_length": 92, "alphanum_fraction": 0.6052376334}
import NextAuth from 'next-auth';
import Providers from 'next-auth/providers';
import { verifyPassword } from 'helpers/passwordHelpers';
import { connectDatabase } from 'helpers/databaseHelpers';

export default NextAuth({
  session: {
    jwt: true,
  },
  providers: [
    Providers.Credentials({
      async authorize({ email, password }) {
        const client = await connectDatabase();

        const accountsCollection = client.db().collection('accounts');

        const account = await accountsCollection.findOne({ email: email });

        if (!account) {
          client.close();
          throw new Error(
            "Sorry, but we can't find an account with this email address. Please try again."
          );
        }

        const isValid = await verifyPassword(password, account.password);

        if (!isValid) {
          client.close();
          throw new Error('Incorrect password. Please try again.');
        }

        client.close();
        return { email: account.email };
      },
    }),
  ],
});
