Initial commit v1.1
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
import { betterAuth } from 'better-auth'
|
||||
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
|
||||
import { magicLink } from 'better-auth/plugins'
|
||||
import { db } from './db'
|
||||
import * as schema from './db/schema'
|
||||
import { sendEmail } from './email'
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
provider: 'pg',
|
||||
schema: {
|
||||
user: schema.user,
|
||||
session: schema.session,
|
||||
verification: schema.verification,
|
||||
},
|
||||
}),
|
||||
|
||||
// Disable password-based signup — invite-only, magic link only
|
||||
emailAndPassword: { enabled: false },
|
||||
|
||||
plugins: [
|
||||
magicLink({
|
||||
disableSignUp: true, // only existing (invited) users can sign in
|
||||
sendMagicLink: async ({ email, url }) => {
|
||||
await sendEmail({
|
||||
to: email,
|
||||
subject: 'Sign in to MulliganMates',
|
||||
html: `
|
||||
<div style="font-family:sans-serif;max-width:480px;margin:0 auto;padding:32px">
|
||||
<div style="font-size:32px;margin-bottom:8px">⛳</div>
|
||||
<h1 style="font-size:24px;font-weight:700;color:#16a34a;margin:0 0 8px">MulliganMates</h1>
|
||||
<p style="color:#374151;margin:0 0 24px">Click the button below to sign in. This link expires in 1 hour.</p>
|
||||
<a href="${url}"
|
||||
style="display:inline-block;background:#16a34a;color:#fff;text-decoration:none;
|
||||
font-weight:600;font-size:16px;padding:14px 28px;border-radius:8px">
|
||||
Sign in
|
||||
</a>
|
||||
<p style="color:#6b7280;font-size:13px;margin-top:24px">
|
||||
Or copy this link:<br>
|
||||
<a href="${url}" style="color:#16a34a;word-break:break-all">${url}</a>
|
||||
</p>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
user: {
|
||||
additionalFields: {
|
||||
handicapIndex: {
|
||||
type: 'number',
|
||||
nullable: true,
|
||||
fieldName: 'handicap_index',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export type Session = typeof auth.$Infer.Session
|
||||
Reference in New Issue
Block a user