Repository navigation
Expand file tree
/
Copy pathauth.ts
More file actions
74 lines (71 loc) · 2.21 KB
/
Copy pathauth.ts
File metadata and controls
74 lines (71 loc) · 2.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
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
72
73
74
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { prisma } from "./lib/prisma";
import { nextCookies } from "better-auth/next-js";
import { oAuthProxy } from "better-auth/plugins";
import resend from "./lib/resend";
import ForgotPasswordTemplate from "./components/shared/Email/ForgotPasswordTemplate";
import EmailVerificationTemplate from "./components/shared/Email/EmailVerificationTemplate";
const authUrl = process.env.BETTER_AUTH_URL;
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
//password reset
sendResetPassword: async ({ user, url }) => {
const { error } = await resend.emails.send({
from: "Ambrosia <auth@ambrosia.sainte.cloud>",
to: user.email,
subject: "Reset your password",
react: ForgotPasswordTemplate({ firstName: user.name, resetLink: url }),
});
if (error) throw error;
},
revokeSessionsOnPasswordReset: true,
},
emailVerification: {
sendOnSignUp: true,
sendOnSignIn: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({ user, url }) => {
const { error } = await resend.emails.send({
from: "Ambrosia <onboarding@ambrosia.sainte.cloud>",
to: user.email,
subject: "verify your email",
react: EmailVerificationTemplate({
firstName: user.email,
verificationLink: url,
}),
});
if (error) throw error;
},
},
user: {
additionalFields: {
isOnboarded: {
type: "boolean",
defaultValue: false,
required: false,
},
focusAreas: { type: "string[]", defaultValue: [], required: false },
aiEnabled: { type: "boolean", defaultValue: false, required: false },
},
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},
trustedOrigins: [authUrl!],
plugins: [
oAuthProxy({
productionURL: process.env.BETTER_AUTH_URL,
secret: process.env.OAUTH_PROXY_SECRET,
}),
nextCookies(),
],
});