import type { NextAuthConfig } from 'next-auth' import Credentials from 'next-auth/providers/credentials' import Google from 'next-auth/providers/google' import Github from 'next-auth/providers/github' //import Facebook from 'next-auth/providers/facebook' //import Twitter from 'next-auth/providers/twitter' import { LoginSchema } from '@/schemas' import bcrypt from 'bcryptjs' import { getUserByEmail } from '@/data/user' import { env } from 'process' export default { secret: env.AUTH_SECRET, providers: [ Google({ clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }), Github({ clientId: env.GITHUB_CLIENT_ID, clientSecret: env.GITHUB_CLIENT_SECRET, }), //Twitter({}), /*Facebook({ clientId: env.FACEBOOK_CLIENT_ID, clientSecret: env.FACEBOOK_CLIENT_SECRET, }),*/ Credentials({ // @ts-ignore async authorize (credentials) { const validatedFields = LoginSchema.safeParse(credentials) if (validatedFields.success) { const { email, password } = validatedFields.data const user = await getUserByEmail(email) if (!user || !user.password) return null const passwordMatch: boolean = await bcrypt.compare(password, user.password) if (passwordMatch) return user } return null }, })], } satisfies NextAuthConfig