6975a9f97e
- src/lib/email.ts: HTML templates for 4 email types (Second Brain design) - Welcome email on user registration (Better Auth databaseHooks) - Course access email when admin grants enrollment - Homework submitted email to all admins/curators (first submission only) - Feedback received email to student with feedback text and lesson link - Update TECHNICAL.md: Resend domain, from-address, email vars, Stage 3 summary Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { betterAuth } from "better-auth";
|
|
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
import { admin } from "better-auth/plugins";
|
|
import { prisma } from "./prisma";
|
|
import bcrypt from "bcryptjs";
|
|
import { sendWelcomeEmail } from "./email";
|
|
|
|
export const auth = betterAuth({
|
|
database: prismaAdapter(prisma, {
|
|
provider: "postgresql",
|
|
}),
|
|
emailAndPassword: {
|
|
enabled: true,
|
|
requireEmailVerification: true,
|
|
password: {
|
|
hash: (password) => bcrypt.hash(password, 10),
|
|
verify: ({ hash, password }) => bcrypt.compare(password, hash),
|
|
},
|
|
},
|
|
databaseHooks: {
|
|
user: {
|
|
create: {
|
|
after: async (user) => {
|
|
await sendWelcomeEmail(user.email, user.name);
|
|
},
|
|
},
|
|
},
|
|
},
|
|
plugins: [
|
|
admin({
|
|
defaultRole: "student",
|
|
adminRoles: ["admin"],
|
|
}),
|
|
],
|
|
trustedOrigins: [
|
|
process.env.BETTER_AUTH_URL ?? "http://localhost:3000",
|
|
"https://school.second-brain.ru",
|
|
],
|
|
user: {
|
|
additionalFields: {
|
|
role: {
|
|
type: "string",
|
|
defaultValue: "student",
|
|
input: false,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
export type Session = typeof auth.$Infer.Session;
|
|
export type User = typeof auth.$Infer.Session.user;
|