-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
50 lines (49 loc) · 1.29 KB
/
auth.ts
File metadata and controls
50 lines (49 loc) · 1.29 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
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { organization } from 'better-auth/plugins';
import { db } from './db/index.js';
import * as schema from './db/schema.js';
import { env } from './lib/config.js';
import { verifyPassword } from './lib/password.js';
import { emailService } from './services/email/index.js';
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
schema,
}),
user: {
additionalFields: {
isAdmin: {
type: 'boolean',
defaultValue: false,
required: true,
input: false,
},
},
},
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BETTER_AUTH_URL,
trustedOrigins: env.CORS_ALLOWED_ORIGINS,
emailAndPassword: {
enabled: true,
password: {
verify: verifyPassword,
},
},
plugins: [
organization({
async sendInvitationEmail(data) {
const inviteLink = `${env.APP_URL}/invite/${data.id}`;
await emailService.sendEmail({
to: data.email,
template: 'organization-invitation',
payload: {
organizationName: data.organization.name,
inviterName: data.inviter.user.name,
inviteLink,
},
});
},
}),
],
});