-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauth.config.ts
29 lines (26 loc) · 1017 Bytes
/
auth.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { NextAuthConfig } from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import { getUserByEmail } from './actions/user.action';
import { LoginSchema } from './schema';
export default {
providers: [
Credentials({
async authorize(credentials) {
const validatedFields = LoginSchema.safeParse(credentials); // again doing validation
if (validatedFields.success) {
// if validation is successfull
// FIXME: fetch password and check user
const { email } = validatedFields.data;
const user = await getUserByEmail(email); // checking if user is present in database
if (!user || !user.password) return null; // password will be null when user has registered using google or github
// const passwordsMatch = await bcrypt.compare(password, user.password); // comparing the hashed password
// if (passwordsMatch) {
// return user;
// }
return user;
}
return null;
},
}),
],
} satisfies NextAuthConfig;