-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathauth.ts
More file actions
35 lines (32 loc) · 989 Bytes
/
Copy pathauth.ts
File metadata and controls
35 lines (32 loc) · 989 Bytes
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
import { PrismaAdapter } from '@auth/prisma-adapter';
import NextAuth from 'next-auth';
import { authConfig } from './auth.config';
import Google from "next-auth/providers/google"
import Credentials from "next-auth/providers/credentials"
import { prismaClientGlobal } from './infra/prisma';
export const { auth, signIn, signOut, handlers } = NextAuth({
...authConfig,
providers: [
Google,
Credentials({
name: 'Impersonate',
credentials: {
email: { label: "Email", type: "email" },
id: { label: "User ID", type: "text" },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.id) {
return null;
}
const user = await prismaClientGlobal.user.findUnique({
where: {
id: credentials.id as string,
email: credentials.email as string
},
});
return user;
},
}),
],
adapter: PrismaAdapter(prismaClientGlobal),
});