-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
71 lines (66 loc) · 2.05 KB
/
auth.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Adapter } from 'next-auth/adapters';
import { PrismaAdapter } from '@auth/prisma-adapter';
import { prisma } from '@/prisma/client';
import NextAuth from 'next-auth';
import GitHub from 'next-auth/providers/github';
import Google from 'next-auth/providers/google';
import Resend from 'next-auth/providers/resend';
import { sendVerificationRequest } from '@/emails/send-verification';
const providers = [
GitHub({
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
Google({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}),
Resend({
apiKey: process.env.RESEND_API_KEY as string,
from: process.env.DEFAULT_EMAIL_FROM!,
sendVerificationRequest,
}),
];
export const { auth, handlers, signIn, signOut } = NextAuth({
debug: true, // TODO: Remove this in production
session: {
strategy: 'jwt',
},
callbacks: {
session: async ({ session, token }) => {
const user = session?.user
? await prisma.user.findUnique({ where: { email: session.user.email } })
: null;
session = {
...session,
user: {
name: user?.name,
email: user?.email || '',
image: user?.image,
emailVerified: user?.emailVerified || null,
id: token.sub || '',
},
};
return session;
},
authorized: ({ request, auth }) => {
if (
request.nextUrl.pathname.startsWith('/') &&
!request.nextUrl.pathname.includes('/api/uploadthing') &&
!request.nextUrl.pathname.includes('/auth/')
) {
return false;
}
return true;
},
},
providers,
adapter: PrismaAdapter(prisma) as Adapter,
pages: {
signIn: '/auth/signin',
//signOut: '/auth/signout',
//error: '/auth/error', // Error code passed in query string as ?error=
verifyRequest: '/auth/verify-request', // (used for email verification)
//newUser: null, // If set, new users will be directed here on first sign in
},
});