@foldspace-fe/casdoor-next-auth-kit 0.1.22 → 0.1.24
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/README.md +70 -0
- package/dist/auth-role-C35sP1i6.d.ts +40 -0
- package/dist/callback-Da3JC_EN.d.ts +18 -0
- package/dist/casdoor/index.d.ts +3 -8
- package/dist/casdoor/index.js +6 -4
- package/dist/{chunk-GLK4IW22.js → chunk-CSQFNYTS.js} +25 -11
- package/dist/chunk-CSQFNYTS.js.map +1 -0
- package/dist/{chunk-MWXY4JSL.js → chunk-IPJT66SK.js} +19 -11
- package/dist/{chunk-MWXY4JSL.js.map → chunk-IPJT66SK.js.map} +1 -1
- package/dist/chunk-JCQ5P7QZ.js +74 -0
- package/dist/chunk-JCQ5P7QZ.js.map +1 -0
- package/dist/chunk-YHPSOLXM.js +904 -0
- package/dist/chunk-YHPSOLXM.js.map +1 -0
- package/dist/cli-templates-IhA9gjyF.d.ts +31 -0
- package/dist/cli-templates.d.ts +2 -0
- package/dist/cli-templates.js +7 -0
- package/dist/cli-templates.js.map +1 -0
- package/dist/cli.js +52 -557
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -14
- package/dist/index.js +56 -6
- package/dist/next/index.d.ts +3 -3
- package/dist/next/index.js +7 -5
- package/dist/{options-D2YQdRWu.d.ts → options-CpWDszxZ.d.ts} +5 -2
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +4 -18
- package/dist/react/index.js.map +1 -1
- package/dist/skills/casdoor-next-auth-kit/SKILL.md +49 -1
- package/dist/{types-BJv6j3NZ.d.ts → types-COXcI8tx.d.ts} +3 -1
- package/package.json +1 -1
- package/dist/callback-rEWxVGyL.d.ts +0 -12
- package/dist/chunk-FW4WDHNS.js +0 -332
- package/dist/chunk-FW4WDHNS.js.map +0 -1
- package/dist/chunk-GLK4IW22.js.map +0 -1
- package/dist/chunk-T2M5MVPE.js +0 -20
- package/dist/chunk-T2M5MVPE.js.map +0 -1
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
// src/prisma/schema-template.ts
|
|
2
|
+
var AUTH_PRISMA_SCHEMA_MODELS = [
|
|
3
|
+
{
|
|
4
|
+
name: "AuthUser",
|
|
5
|
+
description: "Shared authentication user record",
|
|
6
|
+
fields: [
|
|
7
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
8
|
+
{ name: "email", type: "String?", attributes: ["@unique"] },
|
|
9
|
+
{ name: "name", type: "String?" },
|
|
10
|
+
{ name: "image", type: "String?" },
|
|
11
|
+
{ name: "isAdmin", type: "Boolean", attributes: ["@default(false)"] },
|
|
12
|
+
{ name: "role", type: "String", attributes: ['@default("user")'] },
|
|
13
|
+
{ name: "tokenBalance", type: "Int", attributes: ["@default(0)"] },
|
|
14
|
+
{ name: "isVip", type: "Boolean", attributes: ["@default(false)"] },
|
|
15
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
16
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
17
|
+
],
|
|
18
|
+
blockAttributes: ["@@index([email])"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "AuthMembership",
|
|
22
|
+
description: "Subscription membership snapshot",
|
|
23
|
+
fields: [
|
|
24
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
25
|
+
{ name: "userId", type: "String", attributes: ["@unique"] },
|
|
26
|
+
{ name: "plan", type: "String" },
|
|
27
|
+
{ name: "status", type: "String" },
|
|
28
|
+
{ name: "startsAt", type: "DateTime?" },
|
|
29
|
+
{ name: "endsAt", type: "DateTime?" },
|
|
30
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
31
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
32
|
+
],
|
|
33
|
+
blockAttributes: ["@@index([userId])"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "AuthOrder",
|
|
37
|
+
description: "Commerce order record",
|
|
38
|
+
fields: [
|
|
39
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
40
|
+
{ name: "userId", type: "String" },
|
|
41
|
+
{ name: "kind", type: "String" },
|
|
42
|
+
{ name: "status", type: "String" },
|
|
43
|
+
{ name: "amount", type: "Int" },
|
|
44
|
+
{ name: "currency", type: "String", attributes: ['@default("CNY")'] },
|
|
45
|
+
{ name: "payload", type: "Json?" },
|
|
46
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
47
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
48
|
+
],
|
|
49
|
+
blockAttributes: ["@@index([userId])"]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "AuthSubscription",
|
|
53
|
+
description: "Commerce subscription record",
|
|
54
|
+
fields: [
|
|
55
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
56
|
+
{ name: "userId", type: "String" },
|
|
57
|
+
{ name: "productId", type: "String" },
|
|
58
|
+
{ name: "status", type: "String" },
|
|
59
|
+
{ name: "interval", type: "String" },
|
|
60
|
+
{ name: "startsAt", type: "DateTime?" },
|
|
61
|
+
{ name: "endsAt", type: "DateTime?" },
|
|
62
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
63
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
64
|
+
],
|
|
65
|
+
blockAttributes: ["@@index([userId])", "@@index([productId])"]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "AuthInvoice",
|
|
69
|
+
description: "Commerce invoice record",
|
|
70
|
+
fields: [
|
|
71
|
+
{ name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
|
|
72
|
+
{ name: "userId", type: "String" },
|
|
73
|
+
{ name: "orderId", type: "String?" },
|
|
74
|
+
{ name: "invoiceNo", type: "String", attributes: ["@unique"] },
|
|
75
|
+
{ name: "status", type: "String" },
|
|
76
|
+
{ name: "amount", type: "Int" },
|
|
77
|
+
{ name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
|
|
78
|
+
{ name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
|
|
79
|
+
],
|
|
80
|
+
blockAttributes: ["@@index([userId])", "@@index([orderId])"]
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
function renderField(field) {
|
|
84
|
+
const attributes = field.attributes?.length ? ` ${field.attributes.join(" ")}` : "";
|
|
85
|
+
return ` ${field.name} ${field.type}${attributes}`;
|
|
86
|
+
}
|
|
87
|
+
function renderModel(model) {
|
|
88
|
+
const lines = [
|
|
89
|
+
`/// ${model.description}`,
|
|
90
|
+
`model ${model.name} {`,
|
|
91
|
+
...model.fields.map(renderField)
|
|
92
|
+
];
|
|
93
|
+
if (model.blockAttributes?.length) {
|
|
94
|
+
lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));
|
|
95
|
+
}
|
|
96
|
+
lines.push("}");
|
|
97
|
+
return lines.join("\n");
|
|
98
|
+
}
|
|
99
|
+
function buildAuthPrismaSchemaTemplate(models = AUTH_PRISMA_SCHEMA_MODELS) {
|
|
100
|
+
return [
|
|
101
|
+
"// generated by @foldspace-fe/casdoor-next-auth-kit",
|
|
102
|
+
"// merge these models into the host Prisma schema if you want a dedicated auth module",
|
|
103
|
+
"",
|
|
104
|
+
...models.map(renderModel)
|
|
105
|
+
].join("\n\n");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/core/env.ts
|
|
109
|
+
var AUTH_KIT_ENV_FILES = [".env", ".env.local", ".env.production", ".env.example"];
|
|
110
|
+
var AUTH_KIT_ENV_VARIABLES = [
|
|
111
|
+
{
|
|
112
|
+
key: "APP_URL",
|
|
113
|
+
description: "\u7AD9\u70B9\u5BF9\u5916\u516C\u5F00\u5730\u5740",
|
|
114
|
+
example: "https://your-domain.com",
|
|
115
|
+
local: "http://localhost:5177",
|
|
116
|
+
production: "https://your-domain.com"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: "NEXTAUTH_URL",
|
|
120
|
+
description: "NextAuth \u56DE\u8C03\u5730\u5740",
|
|
121
|
+
example: "http://localhost:5177",
|
|
122
|
+
local: "http://localhost:5177",
|
|
123
|
+
production: "https://your-domain.com"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
key: "NEXTAUTH_SECRET",
|
|
127
|
+
description: "NextAuth JWT secret",
|
|
128
|
+
example: "replace-with-a-random-secret",
|
|
129
|
+
local: "replace-with-a-random-secret",
|
|
130
|
+
production: "replace-with-a-random-secret"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: "GLOBAL_ADMIN_EMAILS",
|
|
134
|
+
description: "\u5168\u5C40\u7BA1\u7406\u5458\u90AE\u7BB1\uFF0C\u9017\u53F7\u5206\u9694",
|
|
135
|
+
example: "admin@example.com",
|
|
136
|
+
local: "admin@example.com",
|
|
137
|
+
production: "admin@example.com"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
key: "AUTH_DEBUG",
|
|
141
|
+
description: "\u662F\u5426\u5F00\u542F\u8BA4\u8BC1\u8C03\u8BD5\u65E5\u5FD7",
|
|
142
|
+
example: "false",
|
|
143
|
+
local: "false",
|
|
144
|
+
production: "false"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
key: "NEXT_PUBLIC_CASDOOR_SERVER_URL",
|
|
148
|
+
description: "Casdoor \u670D\u52A1\u5730\u5740",
|
|
149
|
+
example: "https://auth.example.com",
|
|
150
|
+
local: "https://auth.example.com",
|
|
151
|
+
production: "https://auth.example.com"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
key: "NEXT_PUBLIC_CASDOOR_CLIENT_ID",
|
|
155
|
+
description: "Casdoor client id",
|
|
156
|
+
example: "your-casdoor-client-id",
|
|
157
|
+
local: "your-casdoor-client-id",
|
|
158
|
+
production: "your-casdoor-client-id"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
key: "NEXT_PUBLIC_CASDOOR_APP_NAME",
|
|
162
|
+
description: "Casdoor app name",
|
|
163
|
+
example: "your-app-name",
|
|
164
|
+
local: "your-app-name",
|
|
165
|
+
production: "your-app-name"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
key: "NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME",
|
|
169
|
+
description: "Casdoor organization name",
|
|
170
|
+
example: "your-org-name",
|
|
171
|
+
local: "your-org-name",
|
|
172
|
+
production: "your-org-name"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: "NEXT_PUBLIC_CASDOOR_REDIRECT_PATH",
|
|
176
|
+
description: "Casdoor OAuth \u56DE\u8C03\u8DEF\u5F84",
|
|
177
|
+
example: "/callback",
|
|
178
|
+
local: "/callback",
|
|
179
|
+
production: "/callback"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
key: "NEXT_PUBLIC_CASDOOR_SIGNIN_PATH",
|
|
183
|
+
description: "Casdoor authorize \u8DEF\u5F84",
|
|
184
|
+
example: "/login/oauth/authorize",
|
|
185
|
+
local: "/login/oauth/authorize",
|
|
186
|
+
production: "/login/oauth/authorize"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: "NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH",
|
|
190
|
+
description: "\u6CE8\u9500\u540E\u8DF3\u8F6C\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u9996\u9875",
|
|
191
|
+
example: "/",
|
|
192
|
+
local: "/",
|
|
193
|
+
production: "/"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
key: "NEXT_PUBLIC_BILLING_PURCHASABLE_IDS",
|
|
197
|
+
description: "Billing \u53EF\u8D2D\u4E70\u9879\u767D\u540D\u5355\uFF0C\u9017\u53F7\u5206\u9694",
|
|
198
|
+
example: "membership-monthly,credits-50",
|
|
199
|
+
local: "membership-monthly,credits-50",
|
|
200
|
+
production: "membership-monthly,credits-50"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
key: "NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN",
|
|
204
|
+
description: "Casdoor \u9759\u6001\u8D44\u6E90 origin",
|
|
205
|
+
example: "https://casdoor-static.foldspace.cn",
|
|
206
|
+
local: "https://casdoor-static.foldspace.cn",
|
|
207
|
+
production: "https://casdoor-static.foldspace.cn"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
key: "CASDOOR_CLIENT_SECRET",
|
|
211
|
+
description: "Casdoor client secret",
|
|
212
|
+
example: "your-casdoor-client-secret",
|
|
213
|
+
local: "your-casdoor-client-secret",
|
|
214
|
+
production: "your-casdoor-client-secret"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
key: "BILLING_PAYMENT_SUCCESS_DEBUG",
|
|
218
|
+
description: "\u662F\u5426\u6253\u5370 payment-success \u8C03\u8BD5\u65E5\u5FD7",
|
|
219
|
+
example: "false",
|
|
220
|
+
local: "false",
|
|
221
|
+
production: "false"
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
function stringifyEnvValue(value) {
|
|
225
|
+
if (value === "") {
|
|
226
|
+
return '""';
|
|
227
|
+
}
|
|
228
|
+
if (/^[A-Za-z0-9_./:-]+$/.test(value)) {
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
return JSON.stringify(value);
|
|
232
|
+
}
|
|
233
|
+
function stripQuotes(value) {
|
|
234
|
+
const trimmed = value.trim();
|
|
235
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
236
|
+
return trimmed.slice(1, -1);
|
|
237
|
+
}
|
|
238
|
+
return trimmed;
|
|
239
|
+
}
|
|
240
|
+
function parseEnvKeys(content) {
|
|
241
|
+
const keys = /* @__PURE__ */ new Set();
|
|
242
|
+
for (const line of content.split(/\r?\n/)) {
|
|
243
|
+
const trimmed = line.trim();
|
|
244
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const separatorIndex = trimmed.indexOf("=");
|
|
248
|
+
if (separatorIndex === -1) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const key = trimmed.slice(0, separatorIndex).trim();
|
|
252
|
+
if (key) {
|
|
253
|
+
keys.add(key);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return keys;
|
|
257
|
+
}
|
|
258
|
+
function readManagedEnvValue(content, key) {
|
|
259
|
+
for (const line of content.split(/\r?\n/)) {
|
|
260
|
+
const trimmed = line.trim();
|
|
261
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const separatorIndex = trimmed.indexOf("=");
|
|
265
|
+
if (separatorIndex === -1) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const currentKey = trimmed.slice(0, separatorIndex).trim();
|
|
269
|
+
if (currentKey !== key) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const rawValue = trimmed.slice(separatorIndex + 1).trim();
|
|
273
|
+
return stripQuotes(rawValue);
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
function getManagedEnvValue(definition, file) {
|
|
278
|
+
if (file === ".env.example") {
|
|
279
|
+
return definition.example;
|
|
280
|
+
}
|
|
281
|
+
if (file === ".env.production") {
|
|
282
|
+
return definition.production ?? definition.example;
|
|
283
|
+
}
|
|
284
|
+
if (file === ".env.local") {
|
|
285
|
+
return definition.local ?? definition.example;
|
|
286
|
+
}
|
|
287
|
+
return definition.base ?? definition.local ?? definition.production ?? definition.example;
|
|
288
|
+
}
|
|
289
|
+
function buildManagedEnvTemplate(file, existingContent = "") {
|
|
290
|
+
const existingKeys = parseEnvKeys(existingContent);
|
|
291
|
+
const lines = existingContent.trimEnd() ? existingContent.trimEnd().split(/\r?\n/) : [];
|
|
292
|
+
const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));
|
|
293
|
+
if (missing.length === 0 && existingContent) {
|
|
294
|
+
return existingContent;
|
|
295
|
+
}
|
|
296
|
+
if (lines.length > 0) {
|
|
297
|
+
lines.push("");
|
|
298
|
+
}
|
|
299
|
+
lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);
|
|
300
|
+
for (const definition of missing) {
|
|
301
|
+
const value = getManagedEnvValue(definition, file);
|
|
302
|
+
lines.push(`# ${definition.description}`);
|
|
303
|
+
lines.push(`${definition.key}=${stringifyEnvValue(value)}`);
|
|
304
|
+
lines.push("");
|
|
305
|
+
}
|
|
306
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
307
|
+
lines.pop();
|
|
308
|
+
}
|
|
309
|
+
return `${lines.join("\n")}
|
|
310
|
+
`;
|
|
311
|
+
}
|
|
312
|
+
function getMissingManagedEnvKeys(content) {
|
|
313
|
+
const existingKeys = parseEnvKeys(content);
|
|
314
|
+
return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(
|
|
315
|
+
(definition) => definition.key
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function sanitizeExistingEnvContent(content) {
|
|
319
|
+
return stripQuotes(content);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/cli/fs.ts
|
|
323
|
+
import fs from "fs";
|
|
324
|
+
import path from "path";
|
|
325
|
+
var generatedHeader = "// generated by @foldspace-fe/casdoor-next-auth-kit\n";
|
|
326
|
+
var customBegin = "// @foldspace-fe/casdoor-next-auth-kit:begin custom";
|
|
327
|
+
var customEnd = "// @foldspace-fe/casdoor-next-auth-kit:end custom";
|
|
328
|
+
function ensureDir(filePath) {
|
|
329
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
330
|
+
}
|
|
331
|
+
function writeGeneratedFile(filePath, content) {
|
|
332
|
+
ensureDir(filePath);
|
|
333
|
+
fs.writeFileSync(filePath, generatedHeader + content, "utf8");
|
|
334
|
+
}
|
|
335
|
+
function writeTextFile(filePath, content) {
|
|
336
|
+
ensureDir(filePath);
|
|
337
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
338
|
+
}
|
|
339
|
+
function exists(filePath) {
|
|
340
|
+
return fs.existsSync(filePath);
|
|
341
|
+
}
|
|
342
|
+
function read(filePath) {
|
|
343
|
+
return fs.readFileSync(filePath, "utf8");
|
|
344
|
+
}
|
|
345
|
+
function preserveCustomBlock(existing, next) {
|
|
346
|
+
const begin = existing.indexOf(customBegin);
|
|
347
|
+
const end = existing.indexOf(customEnd);
|
|
348
|
+
if (begin === -1 || end === -1 || end <= begin) return next;
|
|
349
|
+
const custom = existing.slice(begin, end + customEnd.length);
|
|
350
|
+
const targetBegin = next.indexOf(customBegin);
|
|
351
|
+
const targetEnd = next.indexOf(customEnd);
|
|
352
|
+
if (targetBegin === -1 || targetEnd === -1 || targetEnd <= targetBegin) return next;
|
|
353
|
+
return next.slice(0, targetBegin) + custom + next.slice(targetEnd + customEnd.length);
|
|
354
|
+
}
|
|
355
|
+
function removePath(filePath) {
|
|
356
|
+
fs.rmSync(filePath, { force: true, recursive: true });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/cli/templates.ts
|
|
360
|
+
function authLoginRouteTemplate() {
|
|
361
|
+
return `import { loginHandler } from '../../auth-config';
|
|
362
|
+
|
|
363
|
+
export const dynamic = 'force-dynamic';
|
|
364
|
+
|
|
365
|
+
export const GET = loginHandler;
|
|
366
|
+
`;
|
|
367
|
+
}
|
|
368
|
+
function authSignupRouteTemplate() {
|
|
369
|
+
return `import { signupHandler } from '../../auth-config';
|
|
370
|
+
|
|
371
|
+
export const dynamic = 'force-dynamic';
|
|
372
|
+
|
|
373
|
+
export const GET = signupHandler;
|
|
374
|
+
`;
|
|
375
|
+
}
|
|
376
|
+
function authorizeRouteTemplate() {
|
|
377
|
+
return `import { authorizeHandler } from '../../../auth-config';
|
|
378
|
+
|
|
379
|
+
export const dynamic = 'force-dynamic';
|
|
380
|
+
|
|
381
|
+
export const GET = authorizeHandler;
|
|
382
|
+
`;
|
|
383
|
+
}
|
|
384
|
+
function signupAuthorizeRouteTemplate() {
|
|
385
|
+
return `import { authorizeHandler } from '../../../auth-config';
|
|
386
|
+
|
|
387
|
+
export const dynamic = 'force-dynamic';
|
|
388
|
+
|
|
389
|
+
export const GET = authorizeHandler;
|
|
390
|
+
`;
|
|
391
|
+
}
|
|
392
|
+
function callbackRouteTemplate() {
|
|
393
|
+
return `import { callbackHandler } from '../auth-config';
|
|
394
|
+
|
|
395
|
+
export const dynamic = 'force-dynamic';
|
|
396
|
+
|
|
397
|
+
export const GET = callbackHandler;
|
|
398
|
+
`;
|
|
399
|
+
}
|
|
400
|
+
function logoutRouteTemplate() {
|
|
401
|
+
return `import { logoutHandler } from '../auth-config';
|
|
402
|
+
|
|
403
|
+
export const dynamic = 'force-dynamic';
|
|
404
|
+
|
|
405
|
+
export const GET = logoutHandler;
|
|
406
|
+
`;
|
|
407
|
+
}
|
|
408
|
+
function callbackErrorPageTemplate() {
|
|
409
|
+
return `import { ClearDomainCookiesButton } from './clear-domain-cookies-button';
|
|
410
|
+
|
|
411
|
+
export const dynamic = 'force-dynamic';
|
|
412
|
+
|
|
413
|
+
export default async function CallbackErrorPage({
|
|
414
|
+
searchParams,
|
|
415
|
+
}: {
|
|
416
|
+
searchParams: Promise<{ title?: string; message?: string; details?: string }>;
|
|
417
|
+
}) {
|
|
418
|
+
const params = await searchParams;
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<main
|
|
422
|
+
style={{
|
|
423
|
+
minHeight: '100dvh',
|
|
424
|
+
display: 'flex',
|
|
425
|
+
alignItems: 'center',
|
|
426
|
+
justifyContent: 'center',
|
|
427
|
+
padding: '20px 16px',
|
|
428
|
+
background:
|
|
429
|
+
'radial-gradient(circle at top, rgba(99, 102, 241, 0.12) 0, rgba(99, 102, 241, 0) 38%), linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%)',
|
|
430
|
+
}}
|
|
431
|
+
>
|
|
432
|
+
<section
|
|
433
|
+
style={{
|
|
434
|
+
width: 'min(100%, 400px)',
|
|
435
|
+
borderRadius: 28,
|
|
436
|
+
padding: '24px 20px',
|
|
437
|
+
boxSizing: 'border-box',
|
|
438
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
439
|
+
border: '1px solid rgba(148, 163, 184, 0.2)',
|
|
440
|
+
boxShadow: '0 22px 52px rgba(15, 23, 42, 0.12)',
|
|
441
|
+
textAlign: 'center',
|
|
442
|
+
backdropFilter: 'blur(10px)',
|
|
443
|
+
}}
|
|
444
|
+
>
|
|
445
|
+
<div
|
|
446
|
+
style={{
|
|
447
|
+
width: 52,
|
|
448
|
+
height: 52,
|
|
449
|
+
margin: '0 auto 14px',
|
|
450
|
+
display: 'grid',
|
|
451
|
+
placeItems: 'center',
|
|
452
|
+
borderRadius: 18,
|
|
453
|
+
background: 'linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(249, 115, 22, 0.1))',
|
|
454
|
+
color: '#b91c1c',
|
|
455
|
+
fontSize: 28,
|
|
456
|
+
lineHeight: 1,
|
|
457
|
+
}}
|
|
458
|
+
aria-hidden="true"
|
|
459
|
+
>
|
|
460
|
+
!
|
|
461
|
+
</div>
|
|
462
|
+
<div
|
|
463
|
+
style={{
|
|
464
|
+
display: 'inline-flex',
|
|
465
|
+
alignItems: 'center',
|
|
466
|
+
justifyContent: 'center',
|
|
467
|
+
marginBottom: 12,
|
|
468
|
+
padding: '6px 12px',
|
|
469
|
+
borderRadius: 9999,
|
|
470
|
+
background: 'rgba(254, 226, 226, 0.9)',
|
|
471
|
+
color: '#b91c1c',
|
|
472
|
+
fontSize: 13,
|
|
473
|
+
fontWeight: 600,
|
|
474
|
+
letterSpacing: '0.04em',
|
|
475
|
+
}}
|
|
476
|
+
>
|
|
477
|
+
\u8BA4\u8BC1\u5931\u8D25
|
|
478
|
+
</div>
|
|
479
|
+
<h2 style={{ margin: 0, fontSize: 24, lineHeight: 1.2, color: '#0f172a' }}>{params.title ?? 'Callback Error'}</h2>
|
|
480
|
+
<p style={{ margin: '12px 0 0', color: '#334155', lineHeight: 1.6 }}>{params.message ?? 'Unknown callback failure.'}</p>
|
|
481
|
+
{params.details ? (
|
|
482
|
+
<pre
|
|
483
|
+
style={{
|
|
484
|
+
margin: '14px 0 0',
|
|
485
|
+
maxHeight: 140,
|
|
486
|
+
overflow: 'auto',
|
|
487
|
+
padding: 14,
|
|
488
|
+
borderRadius: 18,
|
|
489
|
+
textAlign: 'left',
|
|
490
|
+
whiteSpace: 'pre-wrap',
|
|
491
|
+
wordBreak: 'break-word',
|
|
492
|
+
background: '#f8fafc',
|
|
493
|
+
color: '#0f172a',
|
|
494
|
+
border: '1px solid rgba(148, 163, 184, 0.18)',
|
|
495
|
+
fontSize: 13,
|
|
496
|
+
lineHeight: 1.6,
|
|
497
|
+
}}
|
|
498
|
+
>
|
|
499
|
+
{params.details}
|
|
500
|
+
</pre>
|
|
501
|
+
) : null}
|
|
502
|
+
${customBegin}
|
|
503
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 20 }}>
|
|
504
|
+
<ClearDomainCookiesButton />
|
|
505
|
+
<a href="/" style={{ display: 'inline-flex', width: '100%', alignItems: 'center', justifyContent: 'center', minHeight: 44, padding: '0 16px', boxSizing: 'border-box', borderRadius: 9999, border: '1px solid rgba(148, 163, 184, 0.35)', color: '#0f172a', textDecoration: 'none', background: 'rgba(248, 250, 252, 0.9)' }}>\u8FD4\u56DE\u9996\u9875</a>
|
|
506
|
+
<a href="/auth/login" style={{ display: 'inline-flex', width: '100%', alignItems: 'center', justifyContent: 'center', minHeight: 44, padding: '0 16px', boxSizing: 'border-box', borderRadius: 9999, border: '1px solid rgba(148, 163, 184, 0.35)', color: '#0f172a', textDecoration: 'none', background: 'rgba(248, 250, 252, 0.9)' }}>\u91CD\u65B0\u767B\u5F55</a>
|
|
507
|
+
<a href="/auth/signup" style={{ display: 'inline-flex', width: '100%', alignItems: 'center', justifyContent: 'center', minHeight: 44, padding: '0 16px', boxSizing: 'border-box', borderRadius: 9999, border: '1px solid rgba(148, 163, 184, 0.35)', color: '#0f172a', textDecoration: 'none', background: 'rgba(248, 250, 252, 0.9)' }}>\u53BB\u6CE8\u518C</a>
|
|
508
|
+
</div>
|
|
509
|
+
${customEnd}
|
|
510
|
+
</section>
|
|
511
|
+
</main>
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
`;
|
|
515
|
+
}
|
|
516
|
+
function callbackErrorClearCookiesButtonTemplate() {
|
|
517
|
+
return `'use client';
|
|
518
|
+
|
|
519
|
+
import { useState } from 'react';
|
|
520
|
+
|
|
521
|
+
const AUTH_COOKIE_NAMES = [
|
|
522
|
+
'auth_origin',
|
|
523
|
+
'auth_redirect',
|
|
524
|
+
'oauth_state',
|
|
525
|
+
'pkce_code_verifier',
|
|
526
|
+
'next-auth.session-token',
|
|
527
|
+
'__Secure-next-auth.session-token',
|
|
528
|
+
'next-auth.csrf-token',
|
|
529
|
+
'__Secure-next-auth.csrf-token',
|
|
530
|
+
'__Host-next-auth.csrf-token',
|
|
531
|
+
];
|
|
532
|
+
|
|
533
|
+
function getPathCandidates(pathname: string): string[] {
|
|
534
|
+
const normalized = pathname.startsWith('/') ? pathname : '/' + pathname;
|
|
535
|
+
const segments = normalized.split('/').filter(Boolean);
|
|
536
|
+
const paths = new Set<string>(['/']);
|
|
537
|
+
|
|
538
|
+
let current = '';
|
|
539
|
+
for (const segment of segments) {
|
|
540
|
+
current += '/' + segment;
|
|
541
|
+
paths.add(current);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return [...paths];
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function getDomainCandidates(hostname: string): string[] {
|
|
548
|
+
const normalized = hostname.toLowerCase();
|
|
549
|
+
if (
|
|
550
|
+
normalized === 'localhost' ||
|
|
551
|
+
normalized.endsWith('.localhost') ||
|
|
552
|
+
/^\\d+\\.\\d+\\.\\d+\\.\\d+$/.test(normalized) ||
|
|
553
|
+
/^\\[[^\\]]+\\]$/.test(normalized)
|
|
554
|
+
) {
|
|
555
|
+
return [];
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const parts = normalized.split('.');
|
|
559
|
+
if (parts.length < 2) {
|
|
560
|
+
return [];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const domains = new Set<string>();
|
|
564
|
+
for (let index = 0; index < parts.length - 1; index++) {
|
|
565
|
+
const suffix = parts.slice(index).join('.');
|
|
566
|
+
domains.add(suffix);
|
|
567
|
+
domains.add('.' + suffix);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return [...domains];
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function expireCookie(name: string, path: string, domain?: string) {
|
|
574
|
+
const pieces = [
|
|
575
|
+
name + '=',
|
|
576
|
+
'Max-Age=0',
|
|
577
|
+
'Expires=Thu, 01 Jan 1970 00:00:00 GMT',
|
|
578
|
+
'Path=' + path,
|
|
579
|
+
'SameSite=Lax',
|
|
580
|
+
];
|
|
581
|
+
|
|
582
|
+
if (domain) {
|
|
583
|
+
pieces.push('Domain=' + domain);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (window.location.protocol === 'https:') {
|
|
587
|
+
pieces.push('Secure');
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
document.cookie = pieces.join('; ');
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
${customBegin}
|
|
594
|
+
export function ClearDomainCookiesButton() {
|
|
595
|
+
const [cleared, setCleared] = useState(false);
|
|
596
|
+
|
|
597
|
+
const handleClick = () => {
|
|
598
|
+
if (typeof document === 'undefined' || typeof window === 'undefined') {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const names = new Set<string>(AUTH_COOKIE_NAMES);
|
|
603
|
+
for (const entry of document.cookie.split(';')) {
|
|
604
|
+
const [rawName] = entry.trim().split('=');
|
|
605
|
+
if (rawName) {
|
|
606
|
+
names.add(rawName);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const pathCandidates = getPathCandidates(window.location.pathname);
|
|
611
|
+
const domainCandidates = getDomainCandidates(window.location.hostname);
|
|
612
|
+
|
|
613
|
+
for (const name of names) {
|
|
614
|
+
for (const path of pathCandidates) {
|
|
615
|
+
expireCookie(name, path);
|
|
616
|
+
for (const domain of domainCandidates) {
|
|
617
|
+
expireCookie(name, path, domain);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
setCleared(true);
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
return (
|
|
626
|
+
<button
|
|
627
|
+
type="button"
|
|
628
|
+
onClick={handleClick}
|
|
629
|
+
disabled={cleared}
|
|
630
|
+
style={{
|
|
631
|
+
display: 'inline-flex',
|
|
632
|
+
width: '100%',
|
|
633
|
+
alignItems: 'center',
|
|
634
|
+
justifyContent: 'center',
|
|
635
|
+
minHeight: 44,
|
|
636
|
+
padding: '0 16px',
|
|
637
|
+
boxSizing: 'border-box',
|
|
638
|
+
borderRadius: 9999,
|
|
639
|
+
border: '1px solid rgba(148, 163, 184, 0.35)',
|
|
640
|
+
color: '#0f172a',
|
|
641
|
+
background: cleared ? 'rgba(220, 252, 231, 0.92)' : 'rgba(248, 250, 252, 0.9)',
|
|
642
|
+
cursor: cleared ? 'default' : 'pointer',
|
|
643
|
+
}}
|
|
644
|
+
>
|
|
645
|
+
{cleared ? '\u5DF2\u6E05\u7A7A' : '\u6E05\u7A7A\u5F53\u524D\u57DF Cookie'}
|
|
646
|
+
</button>
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
${customEnd}
|
|
650
|
+
`;
|
|
651
|
+
}
|
|
652
|
+
function authConfigTemplate() {
|
|
653
|
+
return `import {
|
|
654
|
+
createCallbackHandler,
|
|
655
|
+
createCasdoorApiProxyHandler,
|
|
656
|
+
createCasdoorCommerceProxyHandler,
|
|
657
|
+
createAuthorizeRouteHandler,
|
|
658
|
+
createLoginRouteHandler,
|
|
659
|
+
createLogoutHandler,
|
|
660
|
+
createNextAuthOptions,
|
|
661
|
+
createSignupRouteHandler,
|
|
662
|
+
type AuthBusinessAdapter,
|
|
663
|
+
type AuthKitConfig,
|
|
664
|
+
type AuthPersistenceAdapter,
|
|
665
|
+
} from '@foldspace-fe/casdoor-next-auth-kit';
|
|
666
|
+
import { isGlobalAdminEmail } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
667
|
+
import { paymentSuccessHandler as billingPaymentSuccessHandler } from '@/lib/billing/payment-success';
|
|
668
|
+
import { paymentFinishedHandler as billingPaymentFinishedHandler } from '@/lib/billing/payment-finished';
|
|
669
|
+
|
|
670
|
+
export function createAuthKitConfig(): AuthKitConfig {
|
|
671
|
+
return {
|
|
672
|
+
appUrl: process.env.APP_URL || '',
|
|
673
|
+
nextauthSecret: process.env.NEXTAUTH_SECRET || 'dev-nextauth-secret',
|
|
674
|
+
logoutRedirectPath: process.env.NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH || '/',
|
|
675
|
+
casdoor: {
|
|
676
|
+
serverUrl: process.env.NEXT_PUBLIC_CASDOOR_SERVER_URL || process.env.CASDOOR_SERVER_URL || '',
|
|
677
|
+
clientId: process.env.NEXT_PUBLIC_CASDOOR_CLIENT_ID || process.env.CASDOOR_CLIENT_ID || '',
|
|
678
|
+
clientSecret: process.env.CASDOOR_CLIENT_SECRET || '',
|
|
679
|
+
appName: process.env.NEXT_PUBLIC_CASDOOR_APP_NAME || '',
|
|
680
|
+
organizationName: process.env.NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME || '',
|
|
681
|
+
redirectPath: process.env.NEXT_PUBLIC_CASDOOR_REDIRECT_PATH || '/callback',
|
|
682
|
+
signinPath: process.env.NEXT_PUBLIC_CASDOOR_SIGNIN_PATH || '/login/oauth/authorize',
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export const authKitConfig = createAuthKitConfig();
|
|
688
|
+
|
|
689
|
+
export const adapter: AuthBusinessAdapter = {
|
|
690
|
+
onUserSync: async (profile) => {
|
|
691
|
+
const email = profile.email ?? null;
|
|
692
|
+
const isAdmin = Boolean(profile.isAdmin) || isGlobalAdminEmail(email);
|
|
693
|
+
|
|
694
|
+
return {
|
|
695
|
+
id: String(profile.id ?? profile.sub ?? email ?? 'casdoor-user'),
|
|
696
|
+
name: profile.name ?? profile.displayName ?? null,
|
|
697
|
+
email,
|
|
698
|
+
image: profile.picture ?? profile.avatarUrl ?? null,
|
|
699
|
+
isAdmin,
|
|
700
|
+
role: isAdmin ? 'admin' : 'user',
|
|
701
|
+
tokenBalance: 2580,
|
|
702
|
+
isVip: true,
|
|
703
|
+
};
|
|
704
|
+
},
|
|
705
|
+
isAdminEmail: isGlobalAdminEmail,
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
export const persistence: AuthPersistenceAdapter = {
|
|
709
|
+
async syncAuthUser(user) {
|
|
710
|
+
console.info('[casdoor-next-auth-kit] syncAuthUser received user', {
|
|
711
|
+
id: user.id,
|
|
712
|
+
email: user.email,
|
|
713
|
+
isAdmin: user.isAdmin,
|
|
714
|
+
role: user.role,
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
async findAuthUser() {
|
|
718
|
+
return null;
|
|
719
|
+
},
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
export const paymentSuccessHandler = billingPaymentSuccessHandler;
|
|
723
|
+
export const paymentFinishedHandler = billingPaymentFinishedHandler;
|
|
724
|
+
|
|
725
|
+
export const loginHandler = createLoginRouteHandler(authKitConfig);
|
|
726
|
+
export const signupHandler = createSignupRouteHandler(authKitConfig);
|
|
727
|
+
export const authorizeHandler = createAuthorizeRouteHandler(authKitConfig);
|
|
728
|
+
export const callbackHandler = createCallbackHandler({
|
|
729
|
+
config: authKitConfig,
|
|
730
|
+
adapter,
|
|
731
|
+
persistence,
|
|
732
|
+
});
|
|
733
|
+
export const logoutHandler = createLogoutHandler(authKitConfig);
|
|
734
|
+
export const authOptions = createNextAuthOptions({
|
|
735
|
+
config: authKitConfig,
|
|
736
|
+
adapter,
|
|
737
|
+
persistence,
|
|
738
|
+
});
|
|
739
|
+
export const apiProxyHandler = createCasdoorApiProxyHandler(authKitConfig, '/auth/api', '/api');
|
|
740
|
+
export const commerceProxyHandler = createCasdoorCommerceProxyHandler(authKitConfig, '/auth/api/commerce', '/api/commerce');
|
|
741
|
+
`;
|
|
742
|
+
}
|
|
743
|
+
function nextAuthRouteTemplate() {
|
|
744
|
+
return `import NextAuth from 'next-auth';
|
|
745
|
+
import { createNextAuthOptions } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
746
|
+
import { adapter, authKitConfig, persistence } from '../../../auth-config';
|
|
747
|
+
|
|
748
|
+
export const dynamic = 'force-dynamic';
|
|
749
|
+
export const runtime = 'nodejs';
|
|
750
|
+
|
|
751
|
+
const handler = NextAuth(
|
|
752
|
+
createNextAuthOptions({
|
|
753
|
+
config: authKitConfig,
|
|
754
|
+
adapter,
|
|
755
|
+
persistence,
|
|
756
|
+
}),
|
|
757
|
+
);
|
|
758
|
+
|
|
759
|
+
export const GET = handler;
|
|
760
|
+
export const POST = handler;
|
|
761
|
+
`;
|
|
762
|
+
}
|
|
763
|
+
function paymentSuccessRouteTemplate() {
|
|
764
|
+
return `import { createBillingPaymentSuccessRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
765
|
+
import { authKitConfig, paymentSuccessHandler } from '../../../auth-config';
|
|
766
|
+
|
|
767
|
+
export const dynamic = 'force-dynamic';
|
|
768
|
+
export const runtime = 'nodejs';
|
|
769
|
+
|
|
770
|
+
export const GET = createBillingPaymentSuccessRouteHandler({
|
|
771
|
+
appUrl: authKitConfig.appUrl,
|
|
772
|
+
fallbackRedirect: '/auth/payment/finished',
|
|
773
|
+
handler: paymentSuccessHandler,
|
|
774
|
+
phase: 'success',
|
|
775
|
+
});
|
|
776
|
+
`;
|
|
777
|
+
}
|
|
778
|
+
function paymentFinishedRouteTemplate() {
|
|
779
|
+
return `import { createBillingPaymentFinishedRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
780
|
+
import { authKitConfig, paymentFinishedHandler } from '../../../auth-config';
|
|
781
|
+
|
|
782
|
+
export const dynamic = 'force-dynamic';
|
|
783
|
+
export const runtime = 'nodejs';
|
|
784
|
+
|
|
785
|
+
export const GET = createBillingPaymentFinishedRouteHandler({
|
|
786
|
+
appUrl: authKitConfig.appUrl,
|
|
787
|
+
fallbackRedirect: '/',
|
|
788
|
+
handler: paymentFinishedHandler,
|
|
789
|
+
phase: 'finished',
|
|
790
|
+
});
|
|
791
|
+
`;
|
|
792
|
+
}
|
|
793
|
+
function billingPaymentSuccessHandlerTemplate() {
|
|
794
|
+
return `import type { BillingPaymentSuccessHandler } from '@foldspace-fe/casdoor-next-auth-kit/billing';
|
|
795
|
+
|
|
796
|
+
${customBegin}
|
|
797
|
+
const paymentSuccessHandlerImpl: BillingPaymentSuccessHandler = async (context) => {
|
|
798
|
+
console.info('[casdoor-next-auth-kit] payment success callback received', {
|
|
799
|
+
paymentId: context.paymentId,
|
|
800
|
+
orderId: context.orderId,
|
|
801
|
+
status: context.status,
|
|
802
|
+
redirectTo: context.redirectTo,
|
|
803
|
+
});
|
|
804
|
+
return;
|
|
805
|
+
};
|
|
806
|
+
${customEnd}
|
|
807
|
+
|
|
808
|
+
export const paymentSuccessHandler: BillingPaymentSuccessHandler = paymentSuccessHandlerImpl;
|
|
809
|
+
`;
|
|
810
|
+
}
|
|
811
|
+
function billingPaymentFinishedHandlerTemplate() {
|
|
812
|
+
return `import type { BillingPaymentFinishedHandler } from '@foldspace-fe/casdoor-next-auth-kit/billing';
|
|
813
|
+
|
|
814
|
+
${customBegin}
|
|
815
|
+
const paymentFinishedHandlerImpl: BillingPaymentFinishedHandler = async (context) => {
|
|
816
|
+
console.info('[casdoor-next-auth-kit] payment finished callback received', {
|
|
817
|
+
paymentId: context.paymentId,
|
|
818
|
+
orderId: context.orderId,
|
|
819
|
+
status: context.status,
|
|
820
|
+
redirectTo: context.redirectTo,
|
|
821
|
+
});
|
|
822
|
+
return;
|
|
823
|
+
};
|
|
824
|
+
${customEnd}
|
|
825
|
+
|
|
826
|
+
export const paymentFinishedHandler: BillingPaymentFinishedHandler = paymentFinishedHandlerImpl;
|
|
827
|
+
`;
|
|
828
|
+
}
|
|
829
|
+
function authIndexHtmlTemplate() {
|
|
830
|
+
return `export { AUTH_INDEX_HTML, createAuthIndexHtml } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
831
|
+
`;
|
|
832
|
+
}
|
|
833
|
+
function prismaSchemaTemplate() {
|
|
834
|
+
return buildAuthPrismaSchemaTemplate();
|
|
835
|
+
}
|
|
836
|
+
function apiProxyRouteTemplate() {
|
|
837
|
+
return `import { apiProxyHandler } from '../../../auth-config';
|
|
838
|
+
|
|
839
|
+
export const dynamic = 'force-dynamic';
|
|
840
|
+
|
|
841
|
+
export const GET = apiProxyHandler;
|
|
842
|
+
export const HEAD = apiProxyHandler;
|
|
843
|
+
export const POST = apiProxyHandler;
|
|
844
|
+
export const PUT = apiProxyHandler;
|
|
845
|
+
export const PATCH = apiProxyHandler;
|
|
846
|
+
export const DELETE = apiProxyHandler;
|
|
847
|
+
export const OPTIONS = apiProxyHandler;
|
|
848
|
+
`;
|
|
849
|
+
}
|
|
850
|
+
function commerceProxyRouteTemplate() {
|
|
851
|
+
return `import { commerceProxyHandler } from '../../../../auth-config';
|
|
852
|
+
|
|
853
|
+
export const dynamic = 'force-dynamic';
|
|
854
|
+
|
|
855
|
+
export const GET = commerceProxyHandler;
|
|
856
|
+
export const HEAD = commerceProxyHandler;
|
|
857
|
+
export const POST = commerceProxyHandler;
|
|
858
|
+
export const PUT = commerceProxyHandler;
|
|
859
|
+
export const PATCH = commerceProxyHandler;
|
|
860
|
+
export const DELETE = commerceProxyHandler;
|
|
861
|
+
export const OPTIONS = commerceProxyHandler;
|
|
862
|
+
`;
|
|
863
|
+
}
|
|
864
|
+
function envTemplate(file, existingContent = "") {
|
|
865
|
+
return buildManagedEnvTemplate(file, existingContent);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export {
|
|
869
|
+
writeGeneratedFile,
|
|
870
|
+
writeTextFile,
|
|
871
|
+
exists,
|
|
872
|
+
read,
|
|
873
|
+
preserveCustomBlock,
|
|
874
|
+
removePath,
|
|
875
|
+
AUTH_PRISMA_SCHEMA_MODELS,
|
|
876
|
+
buildAuthPrismaSchemaTemplate,
|
|
877
|
+
AUTH_KIT_ENV_FILES,
|
|
878
|
+
AUTH_KIT_ENV_VARIABLES,
|
|
879
|
+
readManagedEnvValue,
|
|
880
|
+
getManagedEnvValue,
|
|
881
|
+
buildManagedEnvTemplate,
|
|
882
|
+
getMissingManagedEnvKeys,
|
|
883
|
+
sanitizeExistingEnvContent,
|
|
884
|
+
authLoginRouteTemplate,
|
|
885
|
+
authSignupRouteTemplate,
|
|
886
|
+
authorizeRouteTemplate,
|
|
887
|
+
signupAuthorizeRouteTemplate,
|
|
888
|
+
callbackRouteTemplate,
|
|
889
|
+
logoutRouteTemplate,
|
|
890
|
+
callbackErrorPageTemplate,
|
|
891
|
+
callbackErrorClearCookiesButtonTemplate,
|
|
892
|
+
authConfigTemplate,
|
|
893
|
+
nextAuthRouteTemplate,
|
|
894
|
+
paymentSuccessRouteTemplate,
|
|
895
|
+
paymentFinishedRouteTemplate,
|
|
896
|
+
billingPaymentSuccessHandlerTemplate,
|
|
897
|
+
billingPaymentFinishedHandlerTemplate,
|
|
898
|
+
authIndexHtmlTemplate,
|
|
899
|
+
prismaSchemaTemplate,
|
|
900
|
+
apiProxyRouteTemplate,
|
|
901
|
+
commerceProxyRouteTemplate,
|
|
902
|
+
envTemplate
|
|
903
|
+
};
|
|
904
|
+
//# sourceMappingURL=chunk-YHPSOLXM.js.map
|