sa2kit 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CollisionBalls-DgKtscU2.d.mts +41 -0
- package/dist/CollisionBalls-DgKtscU2.d.ts +41 -0
- package/dist/ConfigService-Oga_zFRS.d.mts +262 -0
- package/dist/ConfigService-Oga_zFRS.d.ts +262 -0
- package/dist/UniversalFileService-CC4d3wkc.d.ts +139 -0
- package/dist/UniversalFileService-CzAE_G4V.d.mts +139 -0
- package/dist/boothVaultService-lKcnyA-u.d.mts +83 -0
- package/dist/boothVaultService-lKcnyA-u.d.ts +83 -0
- package/dist/business/audioDetection/index.d.mts +2 -0
- package/dist/business/audioDetection/index.d.ts +2 -0
- package/dist/business/audioDetection/index.js +1244 -0
- package/dist/business/audioDetection/index.js.map +1 -0
- package/dist/business/audioDetection/index.mjs +1227 -0
- package/dist/business/audioDetection/index.mjs.map +1 -0
- package/dist/business/calendar/index.d.mts +6 -0
- package/dist/business/calendar/index.d.ts +6 -0
- package/dist/business/calendar/index.js +7433 -0
- package/dist/business/calendar/index.js.map +1 -0
- package/dist/business/calendar/index.mjs +7257 -0
- package/dist/business/calendar/index.mjs.map +1 -0
- package/dist/business/calendar/routes/index.d.mts +191 -0
- package/dist/business/calendar/routes/index.d.ts +191 -0
- package/dist/business/calendar/routes/index.js +844 -0
- package/dist/business/calendar/routes/index.js.map +1 -0
- package/dist/business/calendar/routes/index.mjs +826 -0
- package/dist/business/calendar/routes/index.mjs.map +1 -0
- package/dist/business/festivalCard/index.d.mts +4 -0
- package/dist/business/festivalCard/index.d.ts +4 -0
- package/dist/business/festivalCard/index.js +1492 -0
- package/dist/business/festivalCard/index.js.map +1 -0
- package/dist/business/festivalCard/index.mjs +1475 -0
- package/dist/business/festivalCard/index.mjs.map +1 -0
- package/dist/business/festivalCard/routes/index.d.mts +42 -0
- package/dist/business/festivalCard/routes/index.d.ts +42 -0
- package/dist/business/festivalCard/routes/index.js +361 -0
- package/dist/business/festivalCard/routes/index.js.map +1 -0
- package/dist/business/festivalCard/routes/index.mjs +356 -0
- package/dist/business/festivalCard/routes/index.mjs.map +1 -0
- package/dist/business/festivalCard/server/index.d.mts +120 -0
- package/dist/business/festivalCard/server/index.d.ts +120 -0
- package/dist/business/festivalCard/server/index.js +272 -0
- package/dist/business/festivalCard/server/index.js.map +1 -0
- package/dist/business/festivalCard/server/index.mjs +265 -0
- package/dist/business/festivalCard/server/index.mjs.map +1 -0
- package/dist/business/index.d.mts +34 -0
- package/dist/business/index.d.ts +34 -0
- package/dist/business/index.js +29282 -0
- package/dist/business/index.js.map +1 -0
- package/dist/business/index.mjs +29237 -0
- package/dist/business/index.mjs.map +1 -0
- package/dist/business/mikuContest/ui/web/index.d.mts +2 -0
- package/dist/business/mikuContest/ui/web/index.d.ts +2 -0
- package/dist/business/mikuContest/ui/web/index.js +353 -0
- package/dist/business/mikuContest/ui/web/index.js.map +1 -0
- package/dist/business/mikuContest/ui/web/index.mjs +343 -0
- package/dist/business/mikuContest/ui/web/index.mjs.map +1 -0
- package/dist/business/mikuFireworks3D/index.d.mts +2 -0
- package/dist/business/mikuFireworks3D/index.d.ts +2 -0
- package/dist/business/mikuFireworks3D/index.js +1267 -0
- package/dist/business/mikuFireworks3D/index.js.map +1 -0
- package/dist/business/mikuFireworks3D/index.mjs +1228 -0
- package/dist/business/mikuFireworks3D/index.mjs.map +1 -0
- package/dist/business/mikuFusionGame/index.d.mts +2 -0
- package/dist/business/mikuFusionGame/index.d.ts +2 -0
- package/dist/business/mikuFusionGame/index.js +1208 -0
- package/dist/business/mikuFusionGame/index.js.map +1 -0
- package/dist/business/mikuFusionGame/index.mjs +1195 -0
- package/dist/business/mikuFusionGame/index.mjs.map +1 -0
- package/dist/business/mmd/admin/index.d.mts +487 -0
- package/dist/business/mmd/admin/index.d.ts +487 -0
- package/dist/business/mmd/admin/index.js +1058 -0
- package/dist/business/mmd/admin/index.js.map +1 -0
- package/dist/business/mmd/admin/index.mjs +1027 -0
- package/dist/business/mmd/admin/index.mjs.map +1 -0
- package/dist/business/mmd/index.d.mts +5 -0
- package/dist/business/mmd/index.d.ts +5 -0
- package/dist/business/mmd/index.js +10119 -0
- package/dist/business/mmd/index.js.map +1 -0
- package/dist/business/mmd/index.mjs +10028 -0
- package/dist/business/mmd/index.mjs.map +1 -0
- package/dist/business/mmd/server/index.d.mts +139 -0
- package/dist/business/mmd/server/index.d.ts +139 -0
- package/dist/business/mmd/server/index.js +424 -0
- package/dist/business/mmd/server/index.js.map +1 -0
- package/dist/business/mmd/server/index.mjs +404 -0
- package/dist/business/mmd/server/index.mjs.map +1 -0
- package/dist/business/music/index.d.mts +3 -0
- package/dist/business/music/index.d.ts +3 -0
- package/dist/business/music/index.js +830 -0
- package/dist/business/music/index.js.map +1 -0
- package/dist/business/music/index.mjs +809 -0
- package/dist/business/music/index.mjs.map +1 -0
- package/dist/business/music/server/index.d.mts +1 -0
- package/dist/business/music/server/index.d.ts +1 -0
- package/dist/business/music/server/index.js +194 -0
- package/dist/business/music/server/index.js.map +1 -0
- package/dist/business/music/server/index.mjs +182 -0
- package/dist/business/music/server/index.mjs.map +1 -0
- package/dist/business/navigation/index.d.mts +2 -0
- package/dist/business/navigation/index.d.ts +2 -0
- package/dist/business/navigation/index.js +453 -0
- package/dist/business/navigation/index.js.map +1 -0
- package/dist/business/navigation/index.mjs +443 -0
- package/dist/business/navigation/index.mjs.map +1 -0
- package/dist/business/portfolio/index.d.mts +3 -0
- package/dist/business/portfolio/index.d.ts +3 -0
- package/dist/business/portfolio/index.js +736 -0
- package/dist/business/portfolio/index.js.map +1 -0
- package/dist/business/portfolio/index.mjs +724 -0
- package/dist/business/portfolio/index.mjs.map +1 -0
- package/dist/business/qqbot/server/index.d.mts +167 -0
- package/dist/business/qqbot/server/index.d.ts +167 -0
- package/dist/business/qqbot/server/index.js +394 -0
- package/dist/business/qqbot/server/index.js.map +1 -0
- package/dist/business/qqbot/server/index.mjs +385 -0
- package/dist/business/qqbot/server/index.mjs.map +1 -0
- package/dist/business/qqbot/ui/web/index.d.mts +10 -0
- package/dist/business/qqbot/ui/web/index.d.ts +10 -0
- package/dist/business/qqbot/ui/web/index.js +105 -0
- package/dist/business/qqbot/ui/web/index.js.map +1 -0
- package/dist/business/qqbot/ui/web/index.mjs +99 -0
- package/dist/business/qqbot/ui/web/index.mjs.map +1 -0
- package/dist/business/screenReceiver/index.d.mts +2 -0
- package/dist/business/screenReceiver/index.d.ts +2 -0
- package/dist/business/screenReceiver/index.js +281 -0
- package/dist/business/screenReceiver/index.js.map +1 -0
- package/dist/business/screenReceiver/index.mjs +273 -0
- package/dist/business/screenReceiver/index.mjs.map +1 -0
- package/dist/business/testYourself/admin/index.d.mts +58 -0
- package/dist/business/testYourself/admin/index.d.ts +58 -0
- package/dist/business/testYourself/admin/index.js +1009 -0
- package/dist/business/testYourself/admin/index.js.map +1 -0
- package/dist/business/testYourself/admin/index.mjs +1002 -0
- package/dist/business/testYourself/admin/index.mjs.map +1 -0
- package/dist/business/testYourself/index.d.mts +6 -0
- package/dist/business/testYourself/index.d.ts +6 -0
- package/dist/business/testYourself/index.js +2551 -0
- package/dist/business/testYourself/index.js.map +1 -0
- package/dist/business/testYourself/index.mjs +2531 -0
- package/dist/business/testYourself/index.mjs.map +1 -0
- package/dist/business/testYourself/server/index.d.mts +1029 -0
- package/dist/business/testYourself/server/index.d.ts +1029 -0
- package/dist/business/testYourself/server/index.js +825 -0
- package/dist/business/testYourself/server/index.js.map +1 -0
- package/dist/business/testYourself/server/index.mjs +816 -0
- package/dist/business/testYourself/server/index.mjs.map +1 -0
- package/dist/business/vocaloidBooth/index.d.mts +2 -0
- package/dist/business/vocaloidBooth/index.d.ts +2 -0
- package/dist/business/vocaloidBooth/index.js +172 -0
- package/dist/business/vocaloidBooth/index.js.map +1 -0
- package/dist/business/vocaloidBooth/index.mjs +166 -0
- package/dist/business/vocaloidBooth/index.mjs.map +1 -0
- package/dist/business/vocaloidBooth/server/index.d.mts +111 -0
- package/dist/business/vocaloidBooth/server/index.d.ts +111 -0
- package/dist/business/vocaloidBooth/server/index.js +247 -0
- package/dist/business/vocaloidBooth/server/index.js.map +1 -0
- package/dist/business/vocaloidBooth/server/index.mjs +237 -0
- package/dist/business/vocaloidBooth/server/index.mjs.map +1 -0
- package/dist/business/vocaloidBooth/web/index.d.mts +45 -0
- package/dist/business/vocaloidBooth/web/index.d.ts +45 -0
- package/dist/business/vocaloidBooth/web/index.js +376 -0
- package/dist/business/vocaloidBooth/web/index.js.map +1 -0
- package/dist/business/vocaloidBooth/web/index.mjs +362 -0
- package/dist/business/vocaloidBooth/web/index.mjs.map +1 -0
- package/dist/common/auth/components/index.js +18 -0
- package/dist/common/auth/components/index.js.map +1 -1
- package/dist/common/auth/components/index.mjs +18 -0
- package/dist/common/auth/components/index.mjs.map +1 -1
- package/dist/common/auth/server/index.d.mts +86 -3
- package/dist/common/auth/server/index.d.ts +86 -3
- package/dist/common/auth/server/index.js +614 -1
- package/dist/common/auth/server/index.js.map +1 -1
- package/dist/common/auth/server/index.mjs +599 -3
- package/dist/common/auth/server/index.mjs.map +1 -1
- package/dist/config-BQp3qLAL.d.mts +22 -0
- package/dist/config-BQp3qLAL.d.ts +22 -0
- package/dist/drizzle-schema-BNhqj2AZ.d.mts +1114 -0
- package/dist/drizzle-schema-BNhqj2AZ.d.ts +1114 -0
- package/dist/festivalCardService-D60G-sgr.d.mts +13 -0
- package/dist/festivalCardService-DnLyJpRh.d.ts +13 -0
- package/dist/index-BMgdH5dL.d.mts +1716 -0
- package/dist/index-BO9_Do5y.d.mts +93 -0
- package/dist/index-BO9_Do5y.d.ts +93 -0
- package/dist/index-BSmd4ikf.d.ts +76 -0
- package/dist/index-BSwvWYp2.d.mts +2632 -0
- package/dist/index-Bo_fW3Tl.d.mts +105 -0
- package/dist/index-Bo_fW3Tl.d.ts +105 -0
- package/dist/index-BrKazb8M.d.mts +148 -0
- package/dist/index-BrKazb8M.d.ts +148 -0
- package/dist/index-Bzh6QE4P.d.ts +25 -0
- package/dist/index-C5Ic6eSR.d.mts +25 -0
- package/dist/index-C8i9SIxk.d.ts +2632 -0
- package/dist/index-C_GhVhOT.d.mts +109 -0
- package/dist/index-C_GhVhOT.d.ts +109 -0
- package/dist/index-Cb3UEpG4.d.mts +101 -0
- package/dist/index-CjlkUj01.d.mts +103 -0
- package/dist/index-CucXCBNR.d.mts +302 -0
- package/dist/index-CucXCBNR.d.ts +302 -0
- package/dist/index-DLLPTprx.d.mts +1522 -0
- package/dist/index-DRiZy0dv.d.mts +525 -0
- package/dist/index-DRiZy0dv.d.ts +525 -0
- package/dist/index-Dc_I2t0P.d.mts +103 -0
- package/dist/index-DowAHRIP.d.mts +250 -0
- package/dist/index-DowAHRIP.d.ts +250 -0
- package/dist/index-Dpq_5H2n.d.ts +103 -0
- package/dist/index-Ds2M_9zb.d.ts +101 -0
- package/dist/index-IXMAeTtN.d.ts +1716 -0
- package/dist/index-VFDbZxVM.d.ts +1522 -0
- package/dist/index-jadkp96n.d.ts +103 -0
- package/dist/index-r2-zE3iC.d.mts +76 -0
- package/dist/index.d.mts +10682 -0
- package/dist/index.d.ts +10682 -0
- package/dist/index.js +38233 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +37959 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-B6B210gX.d.mts +270 -0
- package/dist/types-B6B210gX.d.ts +270 -0
- package/dist/types-B7voqjjA.d.mts +51 -0
- package/dist/types-B7voqjjA.d.ts +51 -0
- package/dist/types-Bdnte5EN.d.mts +292 -0
- package/dist/types-C2z_QQPI.d.mts +70 -0
- package/dist/types-C2z_QQPI.d.ts +70 -0
- package/dist/types-HorDyIRv.d.mts +303 -0
- package/dist/types-HorDyIRv.d.ts +303 -0
- package/dist/types-_rFX1atk.d.ts +292 -0
- package/package.json +10 -2
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { authDrizzleSchema } from '../../../chunk-EBHPTFG6.mjs';
|
|
1
|
+
import { account, authDrizzleSchema } from '../../../chunk-EBHPTFG6.mjs';
|
|
2
2
|
export { account, accountRelations, authDrizzleSchema, session, sessionRelations, user, userRelations, userRole, verification, verifications } from '../../../chunk-EBHPTFG6.mjs';
|
|
3
3
|
import '../../../chunk-MAI35PU6.mjs';
|
|
4
4
|
import { betterAuth } from 'better-auth';
|
|
5
5
|
import { drizzleAdapter } from '@better-auth/drizzle-adapter';
|
|
6
6
|
import { bearer, emailOTP, phoneNumber } from 'better-auth/plugins';
|
|
7
|
+
import { and, eq } from 'drizzle-orm';
|
|
8
|
+
import { hashPassword } from 'better-auth/crypto';
|
|
7
9
|
import { toNextJsHandler } from 'better-auth/next-js';
|
|
8
10
|
|
|
9
11
|
// src/common/auth/server/plugins/dev-otp.ts
|
|
@@ -17,6 +19,70 @@ function createDevOtpLogger(enabled) {
|
|
|
17
19
|
}
|
|
18
20
|
var defaultPhoneValidator = (phoneNumber2) => /^1\d{10}$/.test(phoneNumber2);
|
|
19
21
|
var defaultTempEmailFromPhone = (phoneNumber2) => `${phoneNumber2.replace(/\D/g, "")}@phone.sa2kit.local`;
|
|
22
|
+
function createId() {
|
|
23
|
+
return globalThis.crypto?.randomUUID?.() ?? `acc_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
24
|
+
}
|
|
25
|
+
async function upsertCredentialPassword(db, userId, plainPassword) {
|
|
26
|
+
const database = db;
|
|
27
|
+
const now = /* @__PURE__ */ new Date();
|
|
28
|
+
const passwordHash = await hashPassword(plainPassword);
|
|
29
|
+
const existing = await database.select({ id: account.id }).from(account).where(and(eq(account.userId, userId), eq(account.providerId, "credential"))).limit(1);
|
|
30
|
+
if (existing[0]) {
|
|
31
|
+
await database.update(account).set({ password: passwordHash, updatedAt: now }).where(eq(account.id, existing[0].id));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await database.insert(account).values({
|
|
35
|
+
id: createId(),
|
|
36
|
+
accountId: userId,
|
|
37
|
+
providerId: "credential",
|
|
38
|
+
userId,
|
|
39
|
+
password: passwordHash,
|
|
40
|
+
createdAt: now,
|
|
41
|
+
updatedAt: now
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/common/auth/server/phone-signup-intent.ts
|
|
46
|
+
var pendingByPhone = /* @__PURE__ */ new Map();
|
|
47
|
+
var TTL_MS = 5 * 60 * 1e3;
|
|
48
|
+
function normalizePhone(phoneNumber2) {
|
|
49
|
+
return phoneNumber2.replace(/\D/g, "");
|
|
50
|
+
}
|
|
51
|
+
function stashPhoneSignupPassword(phoneNumber2, password) {
|
|
52
|
+
pendingByPhone.set(normalizePhone(phoneNumber2), {
|
|
53
|
+
password,
|
|
54
|
+
expiresAt: Date.now() + TTL_MS
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function consumePhoneSignupPassword(phoneNumber2) {
|
|
58
|
+
const key = normalizePhone(phoneNumber2);
|
|
59
|
+
const entry = pendingByPhone.get(key);
|
|
60
|
+
pendingByPhone.delete(key);
|
|
61
|
+
if (!entry) return void 0;
|
|
62
|
+
if (entry.expiresAt < Date.now()) return void 0;
|
|
63
|
+
return entry.password;
|
|
64
|
+
}
|
|
65
|
+
async function handlePhoneSignupIntentRequest(request) {
|
|
66
|
+
if (request.method !== "POST") {
|
|
67
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
68
|
+
}
|
|
69
|
+
let body;
|
|
70
|
+
try {
|
|
71
|
+
body = await request.json();
|
|
72
|
+
} catch {
|
|
73
|
+
return Response.json({ error: "invalid_json" }, { status: 400 });
|
|
74
|
+
}
|
|
75
|
+
const phoneNumber2 = String(body.phoneNumber ?? "").trim();
|
|
76
|
+
const password = String(body.password ?? "");
|
|
77
|
+
if (!defaultPhoneValidator(phoneNumber2)) {
|
|
78
|
+
return Response.json({ error: "invalid_phone" }, { status: 400 });
|
|
79
|
+
}
|
|
80
|
+
if (password.length < 6) {
|
|
81
|
+
return Response.json({ error: "invalid_password" }, { status: 400 });
|
|
82
|
+
}
|
|
83
|
+
stashPhoneSignupPassword(phoneNumber2, password);
|
|
84
|
+
return Response.json({ ok: true });
|
|
85
|
+
}
|
|
20
86
|
|
|
21
87
|
// src/common/auth/server/create-auth.ts
|
|
22
88
|
function createSa2kitAuth(config) {
|
|
@@ -64,7 +130,13 @@ function createSa2kitAuth(config) {
|
|
|
64
130
|
async sendOTP({ phoneNumber: phone, code }) {
|
|
65
131
|
devLog?.("sms", phone, code);
|
|
66
132
|
if (config.sms?.sendOTP) {
|
|
67
|
-
|
|
133
|
+
await config.sms.sendOTP(phone, code);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async callbackOnVerification({ phoneNumber: phone, user: user2 }) {
|
|
137
|
+
const pendingPassword = consumePhoneSignupPassword(phone);
|
|
138
|
+
if (pendingPassword && user2?.id) {
|
|
139
|
+
await upsertCredentialPassword(config.db, String(user2.id), pendingPassword);
|
|
68
140
|
}
|
|
69
141
|
},
|
|
70
142
|
signUpOnVerification: {
|
|
@@ -76,6 +148,530 @@ function createSa2kitAuth(config) {
|
|
|
76
148
|
});
|
|
77
149
|
return auth;
|
|
78
150
|
}
|
|
151
|
+
|
|
152
|
+
// src/common/auth/server/env/auth-env-catalog.ts
|
|
153
|
+
var AUTH_FEATURES = [
|
|
154
|
+
{
|
|
155
|
+
id: "core",
|
|
156
|
+
name: "\u6838\u5FC3\u8BA4\u8BC1",
|
|
157
|
+
description: "Better Auth \u670D\u52A1\u7AEF\u57FA\u7840\u80FD\u529B\uFF08\u4F1A\u8BDD\u3001Cookie\u3001API \u8DEF\u7531\uFF09",
|
|
158
|
+
envKeys: ["BETTER_AUTH_SECRET", "BETTER_AUTH_URL"]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "client",
|
|
162
|
+
name: "Web \u5BA2\u6237\u7AEF",
|
|
163
|
+
description: "\u6D4F\u89C8\u5668\u7AEF AuthProvider / \u767B\u5F55\u5F39\u7A97\u8BF7\u6C42\u6B63\u786E origin",
|
|
164
|
+
envKeys: ["NEXT_PUBLIC_APP_URL"]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "trusted_origins",
|
|
168
|
+
name: "\u8DE8\u57DF\u4FE1\u4EFB\u6E90",
|
|
169
|
+
description: "\u591A\u57DF\u540D / \u9884\u89C8\u73AF\u5883 CORS \u4E0E Cookie",
|
|
170
|
+
envKeys: ["BETTER_AUTH_TRUSTED_ORIGINS"]
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "sms_phone_otp",
|
|
174
|
+
name: "\u624B\u673A\u77ED\u4FE1 OTP",
|
|
175
|
+
description: "\u624B\u673A\u53F7\u6CE8\u518C / \u767B\u5F55 / \u627E\u56DE\u5BC6\u7801\u7684\u77ED\u4FE1\u9A8C\u8BC1\u7801",
|
|
176
|
+
envKeys: [
|
|
177
|
+
"SA2KIT_SMS_PROVIDER",
|
|
178
|
+
"ALIYUN_SMS_ACCESS_KEY_ID",
|
|
179
|
+
"ALIYUN_SMS_ACCESS_KEY_SECRET",
|
|
180
|
+
"ALIYUN_SMS_SIGN_NAME",
|
|
181
|
+
"ALIYUN_SMS_TEMPLATE_CODE",
|
|
182
|
+
"ALIYUN_SMS_COUNTRY_CODE",
|
|
183
|
+
"ALIYUN_SMS_CODE_VALID_MINUTES",
|
|
184
|
+
"ALIYUN_SMS_ENDPOINT"
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
id: "email_otp",
|
|
189
|
+
name: "\u90AE\u7BB1 OTP",
|
|
190
|
+
description: "\u90AE\u7BB1\u9A8C\u8BC1\u7801\uFF08\u9700\u5728 createSa2kitAuth \u4F20\u5165 email.sendVerificationOTP\uFF09",
|
|
191
|
+
envKeys: ["SA2KIT_EMAIL_PROVIDER"]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "database",
|
|
195
|
+
name: "\u6570\u636E\u5E93",
|
|
196
|
+
description: "Drizzle + PostgreSQL \u6301\u4E45\u5316 user/session\uFF08\u7531\u5BBF\u4E3B\u9879\u76EE\u914D\u7F6E\uFF09",
|
|
197
|
+
envKeys: ["DATABASE_URL"]
|
|
198
|
+
}
|
|
199
|
+
];
|
|
200
|
+
var AUTH_ENV_CATALOG = [
|
|
201
|
+
{
|
|
202
|
+
key: "BETTER_AUTH_SECRET",
|
|
203
|
+
featureId: "core",
|
|
204
|
+
required: true,
|
|
205
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
206
|
+
description: "Better Auth \u7B7E\u540D\u5BC6\u94A5\uFF0C\u81F3\u5C11 32 \u5B57\u7B26\u3002\u53EF\u517C\u5BB9\u8BFB\u53D6 NEXTAUTH_SECRET\u3002",
|
|
207
|
+
example: "openssl rand -base64 32",
|
|
208
|
+
secret: true
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
key: "BETTER_AUTH_URL",
|
|
212
|
+
featureId: "core",
|
|
213
|
+
required: true,
|
|
214
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
215
|
+
description: "\u5BF9\u5916\u53EF\u8BBF\u95EE\u7684\u7AD9\u70B9 URL\uFF08\u542B\u534F\u8BAE\u4E0E\u7AEF\u53E3\uFF09\u3002\u53EF\u56DE\u9000 NEXT_PUBLIC_APP_URL / NEXTAUTH_URL\u3002",
|
|
216
|
+
example: "https://example.com"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
key: "NEXT_PUBLIC_APP_URL",
|
|
220
|
+
featureId: "client",
|
|
221
|
+
required: true,
|
|
222
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
223
|
+
description: "\u6D4F\u89C8\u5668\u7AEF auth client \u7684 baseURL\u3002",
|
|
224
|
+
example: "https://example.com"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
key: "BETTER_AUTH_TRUSTED_ORIGINS",
|
|
228
|
+
featureId: "trusted_origins",
|
|
229
|
+
required: false,
|
|
230
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
231
|
+
description: "\u9017\u53F7\u5206\u9694\u7684\u53EF\u4FE1 origin \u5217\u8868\uFF0C\u7528\u4E8E\u9884\u89C8\u57DF / \u591A\u57DF\u540D\u90E8\u7F72\u3002",
|
|
232
|
+
example: "https://example.com,https://www.example.com"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
key: "SA2KIT_SMS_PROVIDER",
|
|
236
|
+
featureId: "sms_phone_otp",
|
|
237
|
+
required: false,
|
|
238
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
239
|
+
description: "\u77ED\u4FE1 provider\uFF1Aconsole\uFF08\u5F00\u53D1\u65E5\u5FD7\uFF09| aliyun-pnvs\uFF08\u751F\u4EA7\uFF09| none\u3002\u5F00\u53D1\u9ED8\u8BA4 console\uFF0C\u751F\u4EA7\u672A\u914D\u7F6E\u5219\u65E0\u6CD5\u53D1\u77ED\u4FE1\u3002",
|
|
240
|
+
example: "aliyun-pnvs"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
key: "ALIYUN_SMS_ACCESS_KEY_ID",
|
|
244
|
+
featureId: "sms_phone_otp",
|
|
245
|
+
required: false,
|
|
246
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
247
|
+
description: "\u963F\u91CC\u4E91 RAM AccessKey ID\uFF08\u77ED\u4FE1\u8BA4\u8BC1 SendSmsVerifyCode\uFF09\u3002",
|
|
248
|
+
secret: true
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
key: "ALIYUN_SMS_ACCESS_KEY_SECRET",
|
|
252
|
+
featureId: "sms_phone_otp",
|
|
253
|
+
required: false,
|
|
254
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
255
|
+
description: "\u963F\u91CC\u4E91 RAM AccessKey Secret\u3002",
|
|
256
|
+
secret: true
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
key: "ALIYUN_SMS_SIGN_NAME",
|
|
260
|
+
featureId: "sms_phone_otp",
|
|
261
|
+
required: false,
|
|
262
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
263
|
+
description: "\u77ED\u4FE1\u8BA4\u8BC1\u63A7\u5236\u53F0\u8D60\u9001/\u7533\u8BF7\u7684\u7B7E\u540D\u540D\u79F0\u3002",
|
|
264
|
+
example: "\u901F\u901A\u4E92\u8054\u9A8C\u8BC1\u7801"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
key: "ALIYUN_SMS_TEMPLATE_CODE",
|
|
268
|
+
featureId: "sms_phone_otp",
|
|
269
|
+
required: false,
|
|
270
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
271
|
+
description: "\u77ED\u4FE1\u8BA4\u8BC1\u63A7\u5236\u53F0\u8D60\u9001/\u7533\u8BF7\u7684\u6A21\u677F CODE\u3002",
|
|
272
|
+
example: "100001"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
key: "ALIYUN_SMS_COUNTRY_CODE",
|
|
276
|
+
featureId: "sms_phone_otp",
|
|
277
|
+
required: false,
|
|
278
|
+
placement: ["env_file", "runtime_env"],
|
|
279
|
+
description: "\u56FD\u5BB6\u7801\uFF0C\u9ED8\u8BA4 86\uFF08\u4E2D\u56FD\u5927\u9646\uFF09\u3002",
|
|
280
|
+
example: "86"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
key: "ALIYUN_SMS_CODE_VALID_MINUTES",
|
|
284
|
+
featureId: "sms_phone_otp",
|
|
285
|
+
required: false,
|
|
286
|
+
placement: ["env_file", "runtime_env"],
|
|
287
|
+
description: "\u77ED\u4FE1\u6A21\u677F\u4E2D\u5C55\u793A\u7684\u6709\u6548\u5206\u949F\u6570\uFF0C\u9ED8\u8BA4 5\uFF08\u4E0E Better Auth OTP \u6709\u6548\u671F\u72EC\u7ACB\uFF09\u3002",
|
|
288
|
+
example: "5"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
key: "ALIYUN_SMS_ENDPOINT",
|
|
292
|
+
featureId: "sms_phone_otp",
|
|
293
|
+
required: false,
|
|
294
|
+
placement: ["env_file", "runtime_env"],
|
|
295
|
+
description: "\u53EF\u9009\uFF0C\u9ED8\u8BA4 https://dypnsapi.aliyuncs.com"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
key: "SA2KIT_EMAIL_PROVIDER",
|
|
299
|
+
featureId: "email_otp",
|
|
300
|
+
required: false,
|
|
301
|
+
placement: ["env_file", "github_secret", "runtime_env"],
|
|
302
|
+
description: "\u90AE\u7BB1 OTP \u7531\u5BBF\u4E3B\u5B9E\u73B0 config.email.sendVerificationOTP\uFF1B\u6B64\u53D8\u91CF\u4EC5\u7528\u4E8E env \u68C0\u67E5\u63D0\u793A\u3002",
|
|
303
|
+
example: "resend | smtp | console"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
key: "DATABASE_URL",
|
|
307
|
+
featureId: "database",
|
|
308
|
+
required: true,
|
|
309
|
+
placement: ["env_file", "github_secret", "runtime_env", "database"],
|
|
310
|
+
description: "PostgreSQL \u8FDE\u63A5\u4E32\uFF08\u5BBF\u4E3B\u9879\u76EE Drizzle \u4F7F\u7528\uFF0C\u975E sa2kit \u76F4\u63A5\u8BFB\u53D6\uFF09\u3002",
|
|
311
|
+
secret: true
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
key: "SA2KIT_AUTH_LOG_OTP",
|
|
315
|
+
featureId: "sms_phone_otp",
|
|
316
|
+
required: false,
|
|
317
|
+
placement: ["env_file", "runtime_env"],
|
|
318
|
+
description: "\u8BBE\u4E3A 1 \u65F6\u5728\u975E\u751F\u4EA7\u73AF\u5883\u5C06 OTP \u6253\u5370\u5230\u670D\u52A1\u7AEF\u65E5\u5FD7\uFF1B\u751F\u4EA7\u73AF\u5883\u5FFD\u7565\u3002\u8BBE\u4E3A 0 \u53EF\u5173\u95ED\u5F00\u53D1\u65E5\u5FD7\u3002",
|
|
319
|
+
example: "1"
|
|
320
|
+
}
|
|
321
|
+
];
|
|
322
|
+
var AUTH_ENV_ALIASES = {
|
|
323
|
+
BETTER_AUTH_SECRET: ["NEXTAUTH_SECRET"],
|
|
324
|
+
BETTER_AUTH_URL: ["NEXT_PUBLIC_APP_URL", "NEXTAUTH_URL"]
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/common/auth/server/sms/providers/aliyun-pnvs.ts
|
|
328
|
+
async function loadPopCore() {
|
|
329
|
+
try {
|
|
330
|
+
const mod = await import('@alicloud/pop-core');
|
|
331
|
+
return mod.default ?? mod;
|
|
332
|
+
} catch {
|
|
333
|
+
throw new Error(
|
|
334
|
+
"\u542F\u7528 SA2KIT_SMS_PROVIDER=aliyun-pnvs \u9700\u8981\u5B89\u88C5 @alicloud/pop-core\uFF1Apnpm add @alicloud/pop-core"
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function createAliyunPnvsSmsProvider(config) {
|
|
339
|
+
return {
|
|
340
|
+
async sendOTP(phoneNumber2, code) {
|
|
341
|
+
const Core = await loadPopCore();
|
|
342
|
+
const client = new Core({
|
|
343
|
+
accessKeyId: config.accessKeyId,
|
|
344
|
+
accessKeySecret: config.accessKeySecret,
|
|
345
|
+
endpoint: config.endpoint ?? "https://dypnsapi.aliyuncs.com",
|
|
346
|
+
apiVersion: "2017-05-25"
|
|
347
|
+
});
|
|
348
|
+
const minutes = String(config.codeValidMinutes ?? 5);
|
|
349
|
+
const result = await client.request(
|
|
350
|
+
"SendSmsVerifyCode",
|
|
351
|
+
{
|
|
352
|
+
PhoneNumber: phoneNumber2,
|
|
353
|
+
CountryCode: config.countryCode ?? "86",
|
|
354
|
+
SignName: config.signName,
|
|
355
|
+
TemplateCode: config.templateCode,
|
|
356
|
+
TemplateParam: JSON.stringify({ code, min: minutes })
|
|
357
|
+
},
|
|
358
|
+
{ method: "POST" }
|
|
359
|
+
);
|
|
360
|
+
if (result.Code !== "OK" && result.Success !== true) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`\u963F\u91CC\u4E91\u77ED\u4FE1\u8BA4\u8BC1\u53D1\u9001\u5931\u8D25: ${result.Message ?? result.Code ?? "unknown error"}`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/common/auth/server/sms/providers/console.ts
|
|
370
|
+
function createConsoleSmsProvider() {
|
|
371
|
+
return {
|
|
372
|
+
async sendOTP(phoneNumber2, code) {
|
|
373
|
+
console.info(`[sa2kit/auth][sms][console] ${phoneNumber2} => ${code}`);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/common/auth/server/sms/create-sms-provider-from-env.ts
|
|
379
|
+
function readEnv(key) {
|
|
380
|
+
const value = process.env[key];
|
|
381
|
+
return value && value.trim().length > 0 ? value.trim() : void 0;
|
|
382
|
+
}
|
|
383
|
+
function resolveSmsProviderId(explicit) {
|
|
384
|
+
if (explicit) return explicit;
|
|
385
|
+
const fromEnv = readEnv("SA2KIT_SMS_PROVIDER");
|
|
386
|
+
if (fromEnv) return fromEnv;
|
|
387
|
+
if (process.env.NODE_ENV !== "production") return "console";
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
function createSmsProviderFromEnv(options) {
|
|
391
|
+
const providerId = resolveSmsProviderId(options?.providerId);
|
|
392
|
+
if (!providerId || providerId === "none") return void 0;
|
|
393
|
+
if (providerId === "console") {
|
|
394
|
+
return createConsoleSmsProvider();
|
|
395
|
+
}
|
|
396
|
+
if (providerId === "aliyun-pnvs") {
|
|
397
|
+
const accessKeyId = readEnv("ALIYUN_SMS_ACCESS_KEY_ID");
|
|
398
|
+
const accessKeySecret = readEnv("ALIYUN_SMS_ACCESS_KEY_SECRET");
|
|
399
|
+
const signName = readEnv("ALIYUN_SMS_SIGN_NAME");
|
|
400
|
+
const templateCode = readEnv("ALIYUN_SMS_TEMPLATE_CODE");
|
|
401
|
+
if (!accessKeyId || !accessKeySecret || !signName || !templateCode) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
"SA2KIT_SMS_PROVIDER=aliyun-pnvs \u9700\u8981 ALIYUN_SMS_ACCESS_KEY_ID\u3001ALIYUN_SMS_ACCESS_KEY_SECRET\u3001ALIYUN_SMS_SIGN_NAME\u3001ALIYUN_SMS_TEMPLATE_CODE"
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
const codeValidMinutes = Number.parseInt(readEnv("ALIYUN_SMS_CODE_VALID_MINUTES") ?? "5", 10);
|
|
407
|
+
return createAliyunPnvsSmsProvider({
|
|
408
|
+
accessKeyId,
|
|
409
|
+
accessKeySecret,
|
|
410
|
+
signName,
|
|
411
|
+
templateCode,
|
|
412
|
+
countryCode: readEnv("ALIYUN_SMS_COUNTRY_CODE") ?? "86",
|
|
413
|
+
codeValidMinutes: Number.isFinite(codeValidMinutes) ? codeValidMinutes : 5,
|
|
414
|
+
endpoint: readEnv("ALIYUN_SMS_ENDPOINT")
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
throw new Error(`\u672A\u77E5\u7684 SA2KIT_SMS_PROVIDER: ${providerId}`);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/common/auth/server/env/resolve-auth-env.ts
|
|
421
|
+
function readEnv2(key) {
|
|
422
|
+
const value = process.env[key];
|
|
423
|
+
return value && value.trim().length > 0 ? value.trim() : void 0;
|
|
424
|
+
}
|
|
425
|
+
function readEnvWithAliases(key) {
|
|
426
|
+
const direct = readEnv2(key);
|
|
427
|
+
if (direct) return direct;
|
|
428
|
+
for (const alias of AUTH_ENV_ALIASES[key] ?? []) {
|
|
429
|
+
const value = readEnv2(alias);
|
|
430
|
+
if (value) return value;
|
|
431
|
+
}
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
function parseTrustedOrigins(baseURL) {
|
|
435
|
+
const fromEnv = readEnv2("BETTER_AUTH_TRUSTED_ORIGINS");
|
|
436
|
+
const defaults = [baseURL, "http://localhost:3000", "http://127.0.0.1:3000"];
|
|
437
|
+
const extra = fromEnv ? fromEnv.split(",").map((item) => item.trim()).filter(Boolean) : [];
|
|
438
|
+
return [...defaults, ...extra].filter((origin, index, list) => list.indexOf(origin) === index);
|
|
439
|
+
}
|
|
440
|
+
function resolveAuthEnv(input) {
|
|
441
|
+
const baseURL = input.baseURL ?? readEnvWithAliases("BETTER_AUTH_URL") ?? readEnv2("NEXT_PUBLIC_APP_URL") ?? "http://localhost:3000";
|
|
442
|
+
const secret = input.secret ?? readEnvWithAliases("BETTER_AUTH_SECRET") ?? (process.env.NODE_ENV !== "production" ? "dev-better-auth-secret-min-32-chars!!" : void 0);
|
|
443
|
+
if (!secret || secret.length < 32) {
|
|
444
|
+
throw new Error("BETTER_AUTH_SECRET \u81F3\u5C11 32 \u5B57\u7B26\uFF08\u6216\u5F00\u53D1\u73AF\u5883\u4F7F\u7528\u9ED8\u8BA4 dev secret\uFF09");
|
|
445
|
+
}
|
|
446
|
+
const smsProvider = createSmsProviderFromEnv();
|
|
447
|
+
const sms = input.sms ?? (smsProvider ? { sendOTP: smsProvider.sendOTP.bind(smsProvider) } : void 0);
|
|
448
|
+
const config = {
|
|
449
|
+
db: input.db,
|
|
450
|
+
baseURL,
|
|
451
|
+
secret,
|
|
452
|
+
trustedOrigins: input.trustedOrigins ?? parseTrustedOrigins(baseURL),
|
|
453
|
+
basePath: input.basePath,
|
|
454
|
+
sms,
|
|
455
|
+
email: input.email,
|
|
456
|
+
phoneNumberValidator: input.phoneNumberValidator,
|
|
457
|
+
logOtpInDev: input.logOtpInDev ?? (process.env.SA2KIT_AUTH_LOG_OTP === "1" || process.env.NODE_ENV !== "production")
|
|
458
|
+
};
|
|
459
|
+
const envSnapshot = {
|
|
460
|
+
BETTER_AUTH_SECRET: readEnvWithAliases("BETTER_AUTH_SECRET") ? "[set]" : void 0,
|
|
461
|
+
BETTER_AUTH_URL: readEnvWithAliases("BETTER_AUTH_URL"),
|
|
462
|
+
NEXT_PUBLIC_APP_URL: readEnv2("NEXT_PUBLIC_APP_URL"),
|
|
463
|
+
BETTER_AUTH_TRUSTED_ORIGINS: readEnv2("BETTER_AUTH_TRUSTED_ORIGINS"),
|
|
464
|
+
SA2KIT_SMS_PROVIDER: String(resolveSmsProviderId() ?? ""),
|
|
465
|
+
ALIYUN_SMS_ACCESS_KEY_ID: readEnv2("ALIYUN_SMS_ACCESS_KEY_ID") ? "[set]" : void 0,
|
|
466
|
+
ALIYUN_SMS_ACCESS_KEY_SECRET: readEnv2("ALIYUN_SMS_ACCESS_KEY_SECRET") ? "[set]" : void 0,
|
|
467
|
+
ALIYUN_SMS_SIGN_NAME: readEnv2("ALIYUN_SMS_SIGN_NAME"),
|
|
468
|
+
ALIYUN_SMS_TEMPLATE_CODE: readEnv2("ALIYUN_SMS_TEMPLATE_CODE"),
|
|
469
|
+
SA2KIT_EMAIL_PROVIDER: readEnv2("SA2KIT_EMAIL_PROVIDER"),
|
|
470
|
+
DATABASE_URL: readEnv2("DATABASE_URL") ? "[set]" : void 0,
|
|
471
|
+
NODE_ENV: process.env.NODE_ENV
|
|
472
|
+
};
|
|
473
|
+
return { config, envSnapshot };
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/common/auth/server/env/check-auth-env.ts
|
|
477
|
+
function isSet(snapshot, key) {
|
|
478
|
+
const value = snapshot[key];
|
|
479
|
+
return value !== void 0 && value !== "[unset]" && value.length > 0;
|
|
480
|
+
}
|
|
481
|
+
function featureById(id) {
|
|
482
|
+
return AUTH_FEATURES.find((f) => f.id === id);
|
|
483
|
+
}
|
|
484
|
+
function varsForFeature(featureId) {
|
|
485
|
+
return AUTH_ENV_CATALOG.filter((item) => item.featureId === featureId);
|
|
486
|
+
}
|
|
487
|
+
function checkAuthEnv(envSnapshot) {
|
|
488
|
+
const issues = [];
|
|
489
|
+
const enabledFeatures = [];
|
|
490
|
+
const disabledFeatures = [];
|
|
491
|
+
const checkRequiredFeature = (featureId, productionOnly = false) => {
|
|
492
|
+
const feature = featureById(featureId);
|
|
493
|
+
const requiredVars = varsForFeature(featureId).filter((item) => item.required);
|
|
494
|
+
const missing = requiredVars.filter((item) => !isSet(envSnapshot, item.key)).map((item) => item.key);
|
|
495
|
+
if (missing.length === 0) {
|
|
496
|
+
enabledFeatures.push(featureId);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (productionOnly && envSnapshot.NODE_ENV !== "production") {
|
|
500
|
+
disabledFeatures.push(featureId);
|
|
501
|
+
issues.push({
|
|
502
|
+
level: "info",
|
|
503
|
+
featureId,
|
|
504
|
+
featureName: feature.name,
|
|
505
|
+
message: `\u5F00\u53D1\u73AF\u5883\u53EF\u6682\u7F3A\uFF1A${missing.join(", ")}`,
|
|
506
|
+
missingKeys: missing
|
|
507
|
+
});
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
disabledFeatures.push(featureId);
|
|
511
|
+
issues.push({
|
|
512
|
+
level: "error",
|
|
513
|
+
featureId,
|
|
514
|
+
featureName: feature.name,
|
|
515
|
+
message: `\u7F3A\u5C11\u5FC5\u9700\u73AF\u5883\u53D8\u91CF\uFF1A${missing.join(", ")}`,
|
|
516
|
+
missingKeys: missing
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
checkRequiredFeature("core");
|
|
520
|
+
checkRequiredFeature("client", true);
|
|
521
|
+
checkRequiredFeature("database", true);
|
|
522
|
+
const smsFeature = featureById("sms_phone_otp");
|
|
523
|
+
const smsProvider = envSnapshot.SA2KIT_SMS_PROVIDER;
|
|
524
|
+
if (smsProvider === "aliyun-pnvs") {
|
|
525
|
+
const aliyunKeys = [
|
|
526
|
+
"ALIYUN_SMS_ACCESS_KEY_ID",
|
|
527
|
+
"ALIYUN_SMS_ACCESS_KEY_SECRET",
|
|
528
|
+
"ALIYUN_SMS_SIGN_NAME",
|
|
529
|
+
"ALIYUN_SMS_TEMPLATE_CODE"
|
|
530
|
+
];
|
|
531
|
+
const missing = aliyunKeys.filter((key) => !isSet(envSnapshot, key));
|
|
532
|
+
if (missing.length === 0) {
|
|
533
|
+
enabledFeatures.push("sms_phone_otp");
|
|
534
|
+
} else {
|
|
535
|
+
disabledFeatures.push("sms_phone_otp");
|
|
536
|
+
issues.push({
|
|
537
|
+
level: "error",
|
|
538
|
+
featureId: "sms_phone_otp",
|
|
539
|
+
featureName: smsFeature.name,
|
|
540
|
+
message: `SA2KIT_SMS_PROVIDER=aliyun-pnvs \u4F46\u7F3A\u5C11\uFF1A${missing.join(", ")}`,
|
|
541
|
+
missingKeys: missing,
|
|
542
|
+
hints: ["\u5728 GitHub Secrets \u6216 .env.production \u4E2D\u914D\u7F6E ALIYUN_SMS_*"]
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
} else if (smsProvider === "console") {
|
|
546
|
+
enabledFeatures.push("sms_phone_otp");
|
|
547
|
+
if (envSnapshot.NODE_ENV === "production") {
|
|
548
|
+
issues.push({
|
|
549
|
+
level: "warning",
|
|
550
|
+
featureId: "sms_phone_otp",
|
|
551
|
+
featureName: smsFeature.name,
|
|
552
|
+
message: "\u751F\u4EA7\u73AF\u5883\u4ECD\u5728\u4F7F\u7528 SA2KIT_SMS_PROVIDER=console\uFF0C\u9A8C\u8BC1\u7801\u4EC5\u8F93\u51FA\u5230\u65E5\u5FD7\uFF0C\u7528\u6237\u6536\u4E0D\u5230\u77ED\u4FE1\u3002",
|
|
553
|
+
hints: ["\u751F\u4EA7\u8BF7\u6539\u4E3A aliyun-pnvs \u5E76\u914D\u7F6E ALIYUN_SMS_*"]
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
} else {
|
|
557
|
+
disabledFeatures.push("sms_phone_otp");
|
|
558
|
+
issues.push({
|
|
559
|
+
level: envSnapshot.NODE_ENV === "production" ? "warning" : "info",
|
|
560
|
+
featureId: "sms_phone_otp",
|
|
561
|
+
featureName: smsFeature.name,
|
|
562
|
+
message: envSnapshot.NODE_ENV === "production" ? "\u672A\u914D\u7F6E\u77ED\u4FE1 provider\uFF0C\u624B\u673A\u53F7 OTP \u65E0\u6CD5\u9001\u8FBE\uFF08\u7528\u6237\u6536\u4E0D\u5230\u9A8C\u8BC1\u7801\uFF09\u3002" : "\u672A\u914D\u7F6E\u77ED\u4FE1 provider\uFF1B\u5F00\u53D1\u73AF\u5883\u53EF\u8BBE\u7F6E SA2KIT_SMS_PROVIDER=console \u5E76\u5728\u670D\u52A1\u7AEF\u65E5\u5FD7\u67E5\u770B OTP\u3002",
|
|
563
|
+
hints: [
|
|
564
|
+
"\u5F00\u53D1\uFF1ASA2KIT_SMS_PROVIDER=console",
|
|
565
|
+
"\u751F\u4EA7\uFF1ASA2KIT_SMS_PROVIDER=aliyun-pnvs + ALIYUN_SMS_*"
|
|
566
|
+
]
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
if (isSet(envSnapshot, "SA2KIT_EMAIL_PROVIDER")) {
|
|
570
|
+
enabledFeatures.push("email_otp");
|
|
571
|
+
} else {
|
|
572
|
+
disabledFeatures.push("email_otp");
|
|
573
|
+
issues.push({
|
|
574
|
+
level: "info",
|
|
575
|
+
featureId: "email_otp",
|
|
576
|
+
featureName: featureById("email_otp").name,
|
|
577
|
+
message: "\u672A\u58F0\u660E SA2KIT_EMAIL_PROVIDER\uFF1B\u82E5\u9700\u90AE\u7BB1\u9A8C\u8BC1\u7801\u8BF7\u5728 createSa2kitAuth \u914D\u7F6E email.sendVerificationOTP\u3002"
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (isSet(envSnapshot, "BETTER_AUTH_TRUSTED_ORIGINS")) {
|
|
581
|
+
enabledFeatures.push("trusted_origins");
|
|
582
|
+
} else {
|
|
583
|
+
disabledFeatures.push("trusted_origins");
|
|
584
|
+
issues.push({
|
|
585
|
+
level: "info",
|
|
586
|
+
featureId: "trusted_origins",
|
|
587
|
+
featureName: featureById("trusted_origins").name,
|
|
588
|
+
message: "\u672A\u8BBE\u7F6E BETTER_AUTH_TRUSTED_ORIGINS\uFF0C\u4EC5\u4F7F\u7528 baseURL + localhost \u9ED8\u8BA4\u503C\u3002"
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
const ok = !issues.some((issue) => issue.level === "error");
|
|
592
|
+
return { ok, issues, enabledFeatures, disabledFeatures };
|
|
593
|
+
}
|
|
594
|
+
var loggedOnce = false;
|
|
595
|
+
function logAuthEnvReport(report, options) {
|
|
596
|
+
if (loggedOnce && !options?.force) return;
|
|
597
|
+
loggedOnce = true;
|
|
598
|
+
const lines = ["[sa2kit/auth] \u73AF\u5883\u914D\u7F6E\u68C0\u67E5"];
|
|
599
|
+
for (const issue of report.issues) {
|
|
600
|
+
const prefix = issue.level === "error" ? "\u2717" : issue.level === "warning" ? "\u26A0" : "\u25CB";
|
|
601
|
+
lines.push(`${prefix} ${issue.featureName}: ${issue.message}`);
|
|
602
|
+
if (issue.hints?.length) {
|
|
603
|
+
for (const hint of issue.hints) {
|
|
604
|
+
lines.push(` \u2192 ${hint}`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (report.issues.length === 0) {
|
|
609
|
+
lines.push("\u2713 \u6240\u6709\u5DF2\u542F\u7528\u80FD\u529B\u7684\u73AF\u5883\u53D8\u91CF\u5747\u5DF2\u5C31\u7EEA");
|
|
610
|
+
}
|
|
611
|
+
lines.push(` \u5DF2\u542F\u7528: ${report.enabledFeatures.join(", ") || "\u65E0"}`);
|
|
612
|
+
console.info(lines.join("\n"));
|
|
613
|
+
}
|
|
614
|
+
function formatAuthEnvSetupMarkdown(report) {
|
|
615
|
+
const lines = [
|
|
616
|
+
"# sa2kit Auth \u73AF\u5883\u53D8\u91CF",
|
|
617
|
+
"",
|
|
618
|
+
"\u5B8C\u6574\u8BF4\u660E\u89C1 sa2kit \u6587\u6863\uFF1A`docs/auth-env.md`",
|
|
619
|
+
"",
|
|
620
|
+
"## \u529F\u80FD \u2194 \u73AF\u5883\u53D8\u91CF",
|
|
621
|
+
""
|
|
622
|
+
];
|
|
623
|
+
for (const feature of AUTH_FEATURES) {
|
|
624
|
+
lines.push(`### ${feature.name} (\`${feature.id}\`)`);
|
|
625
|
+
lines.push("");
|
|
626
|
+
lines.push(feature.description);
|
|
627
|
+
lines.push("");
|
|
628
|
+
const vars = varsForFeature(feature.id);
|
|
629
|
+
lines.push("| \u53D8\u91CF | \u5FC5\u9700 | \u5B58\u653E\u4F4D\u7F6E | \u8BF4\u660E |");
|
|
630
|
+
lines.push("|------|------|----------|------|");
|
|
631
|
+
for (const item of vars) {
|
|
632
|
+
lines.push(
|
|
633
|
+
`| \`${item.key}\` | ${item.required ? "\u662F" : "\u5426"} | ${item.placement.join(", ")} | ${item.description} |`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
lines.push("");
|
|
637
|
+
}
|
|
638
|
+
if (report) {
|
|
639
|
+
lines.push("## \u5F53\u524D\u68C0\u67E5\u7ED3\u679C");
|
|
640
|
+
lines.push("");
|
|
641
|
+
for (const issue of report.issues) {
|
|
642
|
+
lines.push(`- **${issue.featureName}** (${issue.level}): ${issue.message}`);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return lines.join("\n");
|
|
646
|
+
}
|
|
647
|
+
function checkAuthEnvFromProcessEnv(extraSnapshot) {
|
|
648
|
+
const snapshot = {
|
|
649
|
+
BETTER_AUTH_SECRET: process.env.BETTER_AUTH_SECRET || process.env.NEXTAUTH_SECRET ? "[set]" : void 0,
|
|
650
|
+
BETTER_AUTH_URL: process.env.BETTER_AUTH_URL ?? process.env.NEXT_PUBLIC_APP_URL,
|
|
651
|
+
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
|
|
652
|
+
BETTER_AUTH_TRUSTED_ORIGINS: process.env.BETTER_AUTH_TRUSTED_ORIGINS,
|
|
653
|
+
SA2KIT_SMS_PROVIDER: process.env.SA2KIT_SMS_PROVIDER ?? (process.env.NODE_ENV !== "production" ? "console" : void 0),
|
|
654
|
+
ALIYUN_SMS_ACCESS_KEY_ID: process.env.ALIYUN_SMS_ACCESS_KEY_ID ? "[set]" : void 0,
|
|
655
|
+
ALIYUN_SMS_ACCESS_KEY_SECRET: process.env.ALIYUN_SMS_ACCESS_KEY_SECRET ? "[set]" : void 0,
|
|
656
|
+
ALIYUN_SMS_SIGN_NAME: process.env.ALIYUN_SMS_SIGN_NAME,
|
|
657
|
+
ALIYUN_SMS_TEMPLATE_CODE: process.env.ALIYUN_SMS_TEMPLATE_CODE,
|
|
658
|
+
SA2KIT_EMAIL_PROVIDER: process.env.SA2KIT_EMAIL_PROVIDER,
|
|
659
|
+
DATABASE_URL: process.env.DATABASE_URL ? "[set]" : void 0,
|
|
660
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
661
|
+
...extraSnapshot
|
|
662
|
+
};
|
|
663
|
+
return checkAuthEnv(snapshot);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/common/auth/server/create-auth-from-env.ts
|
|
667
|
+
function createSa2kitAuthFromEnv(input, options) {
|
|
668
|
+
const resolved = resolveAuthEnv(input);
|
|
669
|
+
const report = checkAuthEnv(resolved.envSnapshot);
|
|
670
|
+
if (options?.logEnvReport !== false) {
|
|
671
|
+
logAuthEnvReport(report);
|
|
672
|
+
}
|
|
673
|
+
return createSa2kitAuth(resolved.config);
|
|
674
|
+
}
|
|
79
675
|
function mountNextAuthHandler(auth) {
|
|
80
676
|
return toNextJsHandler(auth);
|
|
81
677
|
}
|
|
@@ -123,6 +719,6 @@ function createSessionValidator(auth) {
|
|
|
123
719
|
};
|
|
124
720
|
}
|
|
125
721
|
|
|
126
|
-
export { createAuthRouteHandlers, createSa2kitAuth, createSessionValidator, defaultPhoneValidator, defaultTempEmailFromPhone, getSessionUser, getSessionUserNumeric, mountAuthHandler, mountNextAuthHandler };
|
|
722
|
+
export { AUTH_ENV_ALIASES, AUTH_ENV_CATALOG, AUTH_FEATURES, checkAuthEnv, checkAuthEnvFromProcessEnv, consumePhoneSignupPassword, createAliyunPnvsSmsProvider, createAuthRouteHandlers, createConsoleSmsProvider, createSa2kitAuth, createSa2kitAuthFromEnv, createSessionValidator, createSmsProviderFromEnv, defaultPhoneValidator, defaultTempEmailFromPhone, formatAuthEnvSetupMarkdown, getSessionUser, getSessionUserNumeric, handlePhoneSignupIntentRequest, logAuthEnvReport, mountAuthHandler, mountNextAuthHandler, resolveAuthEnv, resolveSmsProviderId, stashPhoneSignupPassword, upsertCredentialPassword };
|
|
127
723
|
//# sourceMappingURL=index.mjs.map
|
|
128
724
|
//# sourceMappingURL=index.mjs.map
|