-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
39 lines (38 loc) · 1.21 KB
/
auth.ts
File metadata and controls
39 lines (38 loc) · 1.21 KB
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
30
31
32
33
34
35
36
37
38
39
import type { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import prisma from '@lib/prisma';
import { compare } from 'bcrypt';
import type { User } from '@prisma/generated';
import { RoutesEnum } from '@ui/router/routes.enum';
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
session: { strategy: 'jwt' },
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
email: { label: 'Email', type: 'text' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
if (!credentials) return null;
const user: User | null = await prisma.user.findUnique({
where: { email: credentials.email },
});
if (!user) return null;
const isValid: boolean = await compare(
credentials.password,
user.password
);
if (!isValid) return null;
return { id: user.id, email: user.email };
},
}),
],
pages: {
signIn: RoutesEnum.LOGIN,
signOut: RoutesEnum.LOGIN,
},
secret: process.env.NEXTAUTH_SECRET,
};