-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
41 lines (38 loc) · 1.04 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
import { NextAuthOptions } from "next-auth";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import GoogleProvider from "next-auth/providers/google";
import Stripe from "stripe";
import prisma from "@/db";
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2023-08-16",
});
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
secret: process.env.NEXTAUTH_SECRET,
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
}),
],
events: {
createUser: async ({ user }) => {
const customer = await stripe.customers.create({
email: user.email ?? undefined,
name: user.name ?? undefined,
});
await prisma.user.update({
where: {
id: user.id,
},
data: { stripeCustomerId: customer.id },
});
},
},
callbacks: {
session: async ({ session, token, user }) => {
session.user = user;
return session;
},
},
};