-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
87 lines (80 loc) · 2.18 KB
/
Copy pathauth.ts
File metadata and controls
87 lines (80 loc) · 2.18 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
75
76
77
78
79
80
81
82
83
84
85
86
87
import { betterAuth } from 'better-auth';
import { stripe } from '@better-auth/stripe';
import Stripe from 'stripe';
import { admin } from 'better-auth/plugins';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import Database from 'better-sqlite3';
import { parseAdminUserIds } from './src/lib/server/admin';
import * as schema from './src/lib/server/db/schema';
type Schema = typeof import('./src/lib/server/db/schema');
/**
* CLI 用の Better Auth 設定。
* SvelteKit の仮想モジュール ($app/*) に依存しないように分離。
*/
const PREMIUM_PRICE_ID = {
default: 'price_1SjMfPFomgCAvvs0P7MKz8GT'
} as const;
const TEST_PRICE_LOOKUP_KEY = 'test_daily';
const stripeSecretKey = process.env.SECRET_STRIPE_KEY ?? 'sk_test_placeholder';
const stripeWebhookSecret = process.env.STRIPE_WEBHOOK_SECRET ?? 'whsec_placeholder';
const authBaseUrl =
process.env.BETTER_AUTH_URL ?? process.env.PUBLIC_BETTER_AUTH_URL ?? 'http://localhost:3000';
const adminUserIds = parseAdminUserIds(process.env.ADMIN_USER_IDS);
const stripeClient = new Stripe(stripeSecretKey, {
apiVersion: '2025-11-17.clover'
});
export const auth = betterAuth({
database: drizzleAdapter(new Database('./db.sqlite'), {
schema,
provider: 'sqlite'
}),
baseURL: authBaseUrl,
emailAndPassword: {
enabled: true
},
socialProviders: {
google: {
prompt: "select_account",
clientId: process.env.GOOGLE_CLIENT_ID ?? 'google_client_id_placeholder',
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? 'google_client_secret_placeholder'
}
},
plugins: [
admin({
adminUserIds: adminUserIds.length ? adminUserIds : undefined
}),
stripe({
stripeClient,
stripeWebhookSecret,
createCustomerOnSignUp: true,
subscription: {
enabled: true,
allowReTrialsForDifferentPlans: true,
plans: [
{
name: 'Free',
limits: {
projects: 1,
storage: 1
}
},
{
name: 'Premium',
priceId: PREMIUM_PRICE_ID.default,
freeTrial: {
days: 7
}
},
{
name: 'Test 1 Day',
lookupKey: TEST_PRICE_LOOKUP_KEY,
freeTrial: {
days: 1
}
}
]
}
})
],
secret: process.env.BETTER_AUTH_SECRET
});