@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.
Files changed (36) hide show
  1. package/README.md +70 -0
  2. package/dist/auth-role-C35sP1i6.d.ts +40 -0
  3. package/dist/callback-Da3JC_EN.d.ts +18 -0
  4. package/dist/casdoor/index.d.ts +3 -8
  5. package/dist/casdoor/index.js +6 -4
  6. package/dist/{chunk-GLK4IW22.js → chunk-CSQFNYTS.js} +25 -11
  7. package/dist/chunk-CSQFNYTS.js.map +1 -0
  8. package/dist/{chunk-MWXY4JSL.js → chunk-IPJT66SK.js} +19 -11
  9. package/dist/{chunk-MWXY4JSL.js.map → chunk-IPJT66SK.js.map} +1 -1
  10. package/dist/chunk-JCQ5P7QZ.js +74 -0
  11. package/dist/chunk-JCQ5P7QZ.js.map +1 -0
  12. package/dist/chunk-YHPSOLXM.js +904 -0
  13. package/dist/chunk-YHPSOLXM.js.map +1 -0
  14. package/dist/cli-templates-IhA9gjyF.d.ts +31 -0
  15. package/dist/cli-templates.d.ts +2 -0
  16. package/dist/cli-templates.js +7 -0
  17. package/dist/cli-templates.js.map +1 -0
  18. package/dist/cli.js +52 -557
  19. package/dist/cli.js.map +1 -1
  20. package/dist/index.d.ts +8 -14
  21. package/dist/index.js +56 -6
  22. package/dist/next/index.d.ts +3 -3
  23. package/dist/next/index.js +7 -5
  24. package/dist/{options-D2YQdRWu.d.ts → options-CpWDszxZ.d.ts} +5 -2
  25. package/dist/react/index.d.ts +5 -4
  26. package/dist/react/index.js +4 -18
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/skills/casdoor-next-auth-kit/SKILL.md +49 -1
  29. package/dist/{types-BJv6j3NZ.d.ts → types-COXcI8tx.d.ts} +3 -1
  30. package/package.json +1 -1
  31. package/dist/callback-rEWxVGyL.d.ts +0 -12
  32. package/dist/chunk-FW4WDHNS.js +0 -332
  33. package/dist/chunk-FW4WDHNS.js.map +0 -1
  34. package/dist/chunk-GLK4IW22.js.map +0 -1
  35. package/dist/chunk-T2M5MVPE.js +0 -20
  36. package/dist/chunk-T2M5MVPE.js.map +0 -1
@@ -1,332 +0,0 @@
1
- // src/core/env.ts
2
- var AUTH_KIT_ENV_FILES = [".env", ".env.local", ".env.production", ".env.example"];
3
- var AUTH_KIT_ENV_VARIABLES = [
4
- {
5
- key: "APP_URL",
6
- description: "\u7AD9\u70B9\u5BF9\u5916\u516C\u5F00\u5730\u5740",
7
- example: "https://your-domain.com",
8
- local: "http://localhost:5177",
9
- production: "https://your-domain.com"
10
- },
11
- {
12
- key: "NEXTAUTH_URL",
13
- description: "NextAuth \u56DE\u8C03\u5730\u5740",
14
- example: "http://localhost:5177",
15
- local: "http://localhost:5177",
16
- production: "https://your-domain.com"
17
- },
18
- {
19
- key: "NEXTAUTH_SECRET",
20
- description: "NextAuth JWT secret",
21
- example: "replace-with-a-random-secret",
22
- local: "replace-with-a-random-secret",
23
- production: "replace-with-a-random-secret"
24
- },
25
- {
26
- key: "GLOBAL_ADMIN_EMAILS",
27
- description: "\u5168\u5C40\u7BA1\u7406\u5458\u90AE\u7BB1\uFF0C\u9017\u53F7\u5206\u9694",
28
- example: "admin@example.com",
29
- local: "admin@example.com",
30
- production: "admin@example.com"
31
- },
32
- {
33
- key: "AUTH_DEBUG",
34
- description: "\u662F\u5426\u5F00\u542F\u8BA4\u8BC1\u8C03\u8BD5\u65E5\u5FD7",
35
- example: "false",
36
- local: "false",
37
- production: "false"
38
- },
39
- {
40
- key: "NEXT_PUBLIC_CASDOOR_SERVER_URL",
41
- description: "Casdoor \u670D\u52A1\u5730\u5740",
42
- example: "https://auth.example.com",
43
- local: "https://auth.example.com",
44
- production: "https://auth.example.com"
45
- },
46
- {
47
- key: "NEXT_PUBLIC_CASDOOR_CLIENT_ID",
48
- description: "Casdoor client id",
49
- example: "your-casdoor-client-id",
50
- local: "your-casdoor-client-id",
51
- production: "your-casdoor-client-id"
52
- },
53
- {
54
- key: "NEXT_PUBLIC_CASDOOR_APP_NAME",
55
- description: "Casdoor app name",
56
- example: "your-app-name",
57
- local: "your-app-name",
58
- production: "your-app-name"
59
- },
60
- {
61
- key: "NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME",
62
- description: "Casdoor organization name",
63
- example: "your-org-name",
64
- local: "your-org-name",
65
- production: "your-org-name"
66
- },
67
- {
68
- key: "NEXT_PUBLIC_CASDOOR_REDIRECT_PATH",
69
- description: "Casdoor OAuth \u56DE\u8C03\u8DEF\u5F84",
70
- example: "/callback",
71
- local: "/callback",
72
- production: "/callback"
73
- },
74
- {
75
- key: "NEXT_PUBLIC_CASDOOR_SIGNIN_PATH",
76
- description: "Casdoor authorize \u8DEF\u5F84",
77
- example: "/login/oauth/authorize",
78
- local: "/login/oauth/authorize",
79
- production: "/login/oauth/authorize"
80
- },
81
- {
82
- key: "NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH",
83
- description: "\u6CE8\u9500\u540E\u8DF3\u8F6C\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u9996\u9875",
84
- example: "/",
85
- local: "/",
86
- production: "/"
87
- },
88
- {
89
- key: "NEXT_PUBLIC_BILLING_PURCHASABLE_IDS",
90
- description: "Billing \u53EF\u8D2D\u4E70\u9879\u767D\u540D\u5355\uFF0C\u9017\u53F7\u5206\u9694",
91
- example: "starter-month,credits-1000",
92
- local: "starter-month,credits-1000",
93
- production: "starter-month,credits-1000"
94
- },
95
- {
96
- key: "NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN",
97
- description: "Casdoor \u9759\u6001\u8D44\u6E90 origin",
98
- example: "https://casdoor-static.foldspace.cn",
99
- local: "https://casdoor-static.foldspace.cn",
100
- production: "https://casdoor-static.foldspace.cn"
101
- },
102
- {
103
- key: "CASDOOR_CLIENT_SECRET",
104
- description: "Casdoor client secret",
105
- example: "your-casdoor-client-secret",
106
- local: "your-casdoor-client-secret",
107
- production: "your-casdoor-client-secret"
108
- },
109
- {
110
- key: "BILLING_PAYMENT_SUCCESS_DEBUG",
111
- description: "\u662F\u5426\u6253\u5370 payment-success \u8C03\u8BD5\u65E5\u5FD7",
112
- example: "false",
113
- local: "false",
114
- production: "false"
115
- }
116
- ];
117
- function stringifyEnvValue(value) {
118
- if (value === "") {
119
- return '""';
120
- }
121
- if (/^[A-Za-z0-9_./:-]+$/.test(value)) {
122
- return value;
123
- }
124
- return JSON.stringify(value);
125
- }
126
- function stripQuotes(value) {
127
- const trimmed = value.trim();
128
- if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
129
- return trimmed.slice(1, -1);
130
- }
131
- return trimmed;
132
- }
133
- function parseEnvKeys(content) {
134
- const keys = /* @__PURE__ */ new Set();
135
- for (const line of content.split(/\r?\n/)) {
136
- const trimmed = line.trim();
137
- if (!trimmed || trimmed.startsWith("#")) {
138
- continue;
139
- }
140
- const separatorIndex = trimmed.indexOf("=");
141
- if (separatorIndex === -1) {
142
- continue;
143
- }
144
- const key = trimmed.slice(0, separatorIndex).trim();
145
- if (key) {
146
- keys.add(key);
147
- }
148
- }
149
- return keys;
150
- }
151
- function readManagedEnvValue(content, key) {
152
- for (const line of content.split(/\r?\n/)) {
153
- const trimmed = line.trim();
154
- if (!trimmed || trimmed.startsWith("#")) {
155
- continue;
156
- }
157
- const separatorIndex = trimmed.indexOf("=");
158
- if (separatorIndex === -1) {
159
- continue;
160
- }
161
- const currentKey = trimmed.slice(0, separatorIndex).trim();
162
- if (currentKey !== key) {
163
- continue;
164
- }
165
- const rawValue = trimmed.slice(separatorIndex + 1).trim();
166
- return stripQuotes(rawValue);
167
- }
168
- return null;
169
- }
170
- function getManagedEnvValue(definition, file) {
171
- if (file === ".env.example") {
172
- return definition.example;
173
- }
174
- if (file === ".env.production") {
175
- return definition.production ?? definition.example;
176
- }
177
- if (file === ".env.local") {
178
- return definition.local ?? definition.example;
179
- }
180
- return definition.base ?? definition.local ?? definition.production ?? definition.example;
181
- }
182
- function buildManagedEnvTemplate(file, existingContent = "") {
183
- const existingKeys = parseEnvKeys(existingContent);
184
- const lines = existingContent.trimEnd() ? existingContent.trimEnd().split(/\r?\n/) : [];
185
- const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));
186
- if (missing.length === 0 && existingContent) {
187
- return existingContent;
188
- }
189
- if (lines.length > 0) {
190
- lines.push("");
191
- }
192
- lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);
193
- for (const definition of missing) {
194
- const value = getManagedEnvValue(definition, file);
195
- lines.push(`# ${definition.description}`);
196
- lines.push(`${definition.key}=${stringifyEnvValue(value)}`);
197
- lines.push("");
198
- }
199
- while (lines.length > 0 && lines[lines.length - 1] === "") {
200
- lines.pop();
201
- }
202
- return `${lines.join("\n")}
203
- `;
204
- }
205
- function getMissingManagedEnvKeys(content) {
206
- const existingKeys = parseEnvKeys(content);
207
- return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(
208
- (definition) => definition.key
209
- );
210
- }
211
- function sanitizeExistingEnvContent(content) {
212
- return stripQuotes(content);
213
- }
214
-
215
- // src/prisma/schema-template.ts
216
- var AUTH_PRISMA_SCHEMA_MODELS = [
217
- {
218
- name: "AuthUser",
219
- description: "Shared authentication user record",
220
- fields: [
221
- { name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
222
- { name: "email", type: "String?", attributes: ["@unique"] },
223
- { name: "name", type: "String?" },
224
- { name: "image", type: "String?" },
225
- { name: "isAdmin", type: "Boolean", attributes: ["@default(false)"] },
226
- { name: "tokenBalance", type: "Int", attributes: ["@default(0)"] },
227
- { name: "isVip", type: "Boolean", attributes: ["@default(false)"] },
228
- { name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
229
- { name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
230
- ],
231
- blockAttributes: ["@@index([email])"]
232
- },
233
- {
234
- name: "AuthMembership",
235
- description: "Subscription membership snapshot",
236
- fields: [
237
- { name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
238
- { name: "userId", type: "String", attributes: ["@unique"] },
239
- { name: "plan", type: "String" },
240
- { name: "status", type: "String" },
241
- { name: "startsAt", type: "DateTime?" },
242
- { name: "endsAt", type: "DateTime?" },
243
- { name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
244
- { name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
245
- ],
246
- blockAttributes: ["@@index([userId])"]
247
- },
248
- {
249
- name: "AuthOrder",
250
- description: "Commerce order record",
251
- fields: [
252
- { name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
253
- { name: "userId", type: "String" },
254
- { name: "kind", type: "String" },
255
- { name: "status", type: "String" },
256
- { name: "amount", type: "Int" },
257
- { name: "currency", type: "String", attributes: ['@default("CNY")'] },
258
- { name: "payload", type: "Json?" },
259
- { name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
260
- { name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
261
- ],
262
- blockAttributes: ["@@index([userId])"]
263
- },
264
- {
265
- name: "AuthSubscription",
266
- description: "Commerce subscription record",
267
- fields: [
268
- { name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
269
- { name: "userId", type: "String" },
270
- { name: "productId", type: "String" },
271
- { name: "status", type: "String" },
272
- { name: "interval", type: "String" },
273
- { name: "startsAt", type: "DateTime?" },
274
- { name: "endsAt", type: "DateTime?" },
275
- { name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
276
- { name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
277
- ],
278
- blockAttributes: ["@@index([userId])", "@@index([productId])"]
279
- },
280
- {
281
- name: "AuthInvoice",
282
- description: "Commerce invoice record",
283
- fields: [
284
- { name: "id", type: "String", attributes: ["@id", "@default(cuid())"] },
285
- { name: "userId", type: "String" },
286
- { name: "orderId", type: "String?" },
287
- { name: "invoiceNo", type: "String", attributes: ["@unique"] },
288
- { name: "status", type: "String" },
289
- { name: "amount", type: "Int" },
290
- { name: "createdAt", type: "DateTime", attributes: ["@default(now())"] },
291
- { name: "updatedAt", type: "DateTime", attributes: ["@updatedAt"] }
292
- ],
293
- blockAttributes: ["@@index([userId])", "@@index([orderId])"]
294
- }
295
- ];
296
- function renderField(field) {
297
- const attributes = field.attributes?.length ? ` ${field.attributes.join(" ")}` : "";
298
- return ` ${field.name} ${field.type}${attributes}`;
299
- }
300
- function renderModel(model) {
301
- const lines = [
302
- `/// ${model.description}`,
303
- `model ${model.name} {`,
304
- ...model.fields.map(renderField)
305
- ];
306
- if (model.blockAttributes?.length) {
307
- lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));
308
- }
309
- lines.push("}");
310
- return lines.join("\n");
311
- }
312
- function buildAuthPrismaSchemaTemplate(models = AUTH_PRISMA_SCHEMA_MODELS) {
313
- return [
314
- "// generated by @foldspace-fe/casdoor-next-auth-kit",
315
- "// merge these models into the host Prisma schema if you want a dedicated auth module",
316
- "",
317
- ...models.map(renderModel)
318
- ].join("\n\n");
319
- }
320
-
321
- export {
322
- AUTH_KIT_ENV_FILES,
323
- AUTH_KIT_ENV_VARIABLES,
324
- readManagedEnvValue,
325
- getManagedEnvValue,
326
- buildManagedEnvTemplate,
327
- getMissingManagedEnvKeys,
328
- sanitizeExistingEnvContent,
329
- AUTH_PRISMA_SCHEMA_MODELS,
330
- buildAuthPrismaSchemaTemplate
331
- };
332
- //# sourceMappingURL=chunk-FW4WDHNS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/env.ts","../src/prisma/schema-template.ts"],"sourcesContent":["import type { ManagedEnvFile, ManagedEnvVariableDefinition } from '../types';\n\nexport const AUTH_KIT_ENV_FILES: ManagedEnvFile[] = ['.env', '.env.local', '.env.production', '.env.example'];\n\nexport const AUTH_KIT_ENV_VARIABLES: ManagedEnvVariableDefinition[] = [\n {\n key: 'APP_URL',\n description: '站点对外公开地址',\n example: 'https://your-domain.com',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_URL',\n description: 'NextAuth 回调地址',\n example: 'http://localhost:5177',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_SECRET',\n description: 'NextAuth JWT secret',\n example: 'replace-with-a-random-secret',\n local: 'replace-with-a-random-secret',\n production: 'replace-with-a-random-secret',\n },\n {\n key: 'GLOBAL_ADMIN_EMAILS',\n description: '全局管理员邮箱,逗号分隔',\n example: 'admin@example.com',\n local: 'admin@example.com',\n production: 'admin@example.com',\n },\n {\n key: 'AUTH_DEBUG',\n description: '是否开启认证调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SERVER_URL',\n description: 'Casdoor 服务地址',\n example: 'https://auth.example.com',\n local: 'https://auth.example.com',\n production: 'https://auth.example.com',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_CLIENT_ID',\n description: 'Casdoor client id',\n example: 'your-casdoor-client-id',\n local: 'your-casdoor-client-id',\n production: 'your-casdoor-client-id',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_APP_NAME',\n description: 'Casdoor app name',\n example: 'your-app-name',\n local: 'your-app-name',\n production: 'your-app-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME',\n description: 'Casdoor organization name',\n example: 'your-org-name',\n local: 'your-org-name',\n production: 'your-org-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_REDIRECT_PATH',\n description: 'Casdoor OAuth 回调路径',\n example: '/callback',\n local: '/callback',\n production: '/callback',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SIGNIN_PATH',\n description: 'Casdoor authorize 路径',\n example: '/login/oauth/authorize',\n local: '/login/oauth/authorize',\n production: '/login/oauth/authorize',\n },\n {\n key: 'NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH',\n description: '注销后跳转路径,默认首页',\n example: '/',\n local: '/',\n production: '/',\n },\n {\n key: 'NEXT_PUBLIC_BILLING_PURCHASABLE_IDS',\n description: 'Billing 可购买项白名单,逗号分隔',\n example: 'starter-month,credits-1000',\n local: 'starter-month,credits-1000',\n production: 'starter-month,credits-1000',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN',\n description: 'Casdoor 静态资源 origin',\n example: 'https://casdoor-static.foldspace.cn',\n local: 'https://casdoor-static.foldspace.cn',\n production: 'https://casdoor-static.foldspace.cn',\n },\n {\n key: 'CASDOOR_CLIENT_SECRET',\n description: 'Casdoor client secret',\n example: 'your-casdoor-client-secret',\n local: 'your-casdoor-client-secret',\n production: 'your-casdoor-client-secret',\n },\n {\n key: 'BILLING_PAYMENT_SUCCESS_DEBUG',\n description: '是否打印 payment-success 调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n];\n\nfunction stringifyEnvValue(value: string): string {\n if (value === '') {\n return '\"\"';\n }\n\n if (/^[A-Za-z0-9_./:-]+$/.test(value)) {\n return value;\n }\n\n return JSON.stringify(value);\n}\n\nfunction stripQuotes(value: string): string {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n\n return trimmed;\n}\n\nfunction parseEnvKeys(content: string): Set<string> {\n const keys = new Set<string>();\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n if (key) {\n keys.add(key);\n }\n }\n return keys;\n}\n\nexport function readManagedEnvValue(content: string, key: string): string | null {\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const currentKey = trimmed.slice(0, separatorIndex).trim();\n if (currentKey !== key) {\n continue;\n }\n\n const rawValue = trimmed.slice(separatorIndex + 1).trim();\n return stripQuotes(rawValue);\n }\n\n return null;\n}\n\nexport function getManagedEnvValue(definition: ManagedEnvVariableDefinition, file: ManagedEnvFile): string {\n if (file === '.env.example') {\n return definition.example;\n }\n if (file === '.env.production') {\n return definition.production ?? definition.example;\n }\n if (file === '.env.local') {\n return definition.local ?? definition.example;\n }\n return definition.base ?? definition.local ?? definition.production ?? definition.example;\n}\n\nexport function buildManagedEnvTemplate(file: ManagedEnvFile, existingContent = ''): string {\n const existingKeys = parseEnvKeys(existingContent);\n const lines: string[] = existingContent.trimEnd() ? existingContent.trimEnd().split(/\\r?\\n/) : [];\n const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));\n\n if (missing.length === 0 && existingContent) {\n return existingContent;\n }\n\n if (lines.length > 0) {\n lines.push('');\n }\n\n lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);\n for (const definition of missing) {\n const value = getManagedEnvValue(definition, file);\n lines.push(`# ${definition.description}`);\n lines.push(`${definition.key}=${stringifyEnvValue(value)}`);\n lines.push('');\n }\n\n while (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n return `${lines.join('\\n')}\\n`;\n}\n\nexport function getMissingManagedEnvKeys(content: string): string[] {\n const existingKeys = parseEnvKeys(content);\n return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(\n (definition) => definition.key,\n );\n}\n\nexport function sanitizeExistingEnvContent(content: string): string {\n return stripQuotes(content);\n}\n","import type { PrismaSchemaFieldDefinition, PrismaSchemaModelDefinition } from '../types';\n\nexport const AUTH_PRISMA_SCHEMA_MODELS: PrismaSchemaModelDefinition[] = [\n {\n name: 'AuthUser',\n description: 'Shared authentication user record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'email', type: 'String?', attributes: ['@unique'] },\n { name: 'name', type: 'String?' },\n { name: 'image', type: 'String?' },\n { name: 'isAdmin', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'tokenBalance', type: 'Int', attributes: ['@default(0)'] },\n { name: 'isVip', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([email])'],\n },\n {\n name: 'AuthMembership',\n description: 'Subscription membership snapshot',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String', attributes: ['@unique'] },\n { name: 'plan', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthOrder',\n description: 'Commerce order record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'kind', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'currency', type: 'String', attributes: ['@default(\"CNY\")'] },\n { name: 'payload', type: 'Json?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthSubscription',\n description: 'Commerce subscription record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'productId', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'interval', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([productId])'],\n },\n {\n name: 'AuthInvoice',\n description: 'Commerce invoice record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'orderId', type: 'String?' },\n { name: 'invoiceNo', type: 'String', attributes: ['@unique'] },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([orderId])'],\n },\n];\n\nfunction renderField(field: PrismaSchemaFieldDefinition): string {\n const attributes = field.attributes?.length ? ` ${field.attributes.join(' ')}` : '';\n return ` ${field.name} ${field.type}${attributes}`;\n}\n\nfunction renderModel(model: PrismaSchemaModelDefinition): string {\n const lines = [\n `/// ${model.description}`,\n `model ${model.name} {`,\n ...model.fields.map(renderField),\n ];\n\n if (model.blockAttributes?.length) {\n lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nexport function buildAuthPrismaSchemaTemplate(models: PrismaSchemaModelDefinition[] = AUTH_PRISMA_SCHEMA_MODELS): string {\n return [\n '// generated by @foldspace-fe/casdoor-next-auth-kit',\n '// merge these models into the host Prisma schema if you want a dedicated auth module',\n '',\n ...models.map(renderModel),\n ].join('\\n\\n');\n}\n"],"mappings":";AAEO,IAAM,qBAAuC,CAAC,QAAQ,cAAc,mBAAmB,cAAc;AAErG,IAAM,yBAAyD;AAAA,EACpE;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AA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C;AAC/D,QAAM,QAAQ;AAAA,IACZ,OAAO,MAAM,WAAW;AAAA,IACxB,SAAS,MAAM,IAAI;AAAA,IACnB,GAAG,MAAM,OAAO,IAAI,WAAW;AAAA,EACjC;AAEA,MAAI,MAAM,iBAAiB,QAAQ;AACjC,UAAM,KAAK,GAAG,MAAM,gBAAgB,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;AAAA,EAC1E;AAEA,QAAM,KAAK,GAAG;AACd,SAAO,MAAM,KAAK,IAAI;AACxB;AAEO,SAAS,8BAA8B,SAAwC,2BAAmC;AACvH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,OAAO,IAAI,WAAW;AAAA,EAC3B,EAAE,KAAK,MAAM;AACf;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/next/login.ts","../src/next/signup.ts","../src/next/authorize.ts","../src/next/logout.ts","../src/next/options.ts"],"sourcesContent":["import type { NextRequest } from 'next/server';\nimport type { AuthKitConfig } from '../types';\nimport { createLoginEntryResponse } from '../casdoor/entry';\n\nexport function createLoginRouteHandler(config: AuthKitConfig) {\n return async (request: NextRequest) => createLoginEntryResponse(request, config);\n}\n","import type { NextRequest } from 'next/server';\nimport type { AuthKitConfig } from '../types';\nimport { createSignupEntryResponse } from '../casdoor/entry';\n\nexport function createSignupRouteHandler(config: AuthKitConfig) {\n return async (request: NextRequest) => createSignupEntryResponse(request, config);\n}\n","import type { NextRequest } from 'next/server';\nimport type { AuthKitConfig } from '../types';\nimport { createAuthorizeEntryResponse } from '../casdoor/entry';\n\nexport function createAuthorizeRouteHandler(config: AuthKitConfig) {\n return async (request: NextRequest) => createAuthorizeEntryResponse(request, config);\n}\n","import { NextResponse, type NextRequest } from 'next/server';\nimport type { AuthKitConfig } from '../types';\nimport { isSecureRequest } from '../core/request-security';\nimport { clearAuthRedirectCookie } from '../core/auth-redirect';\nimport { clearPublicOriginCookie } from '../core/public-origin';\n\nfunction getCookieNamesFromHeader(cookieHeader: string | null): string[] {\n if (!cookieHeader) {\n return [];\n }\n\n return cookieHeader\n .split(';')\n .map((part) => part.trim())\n .filter(Boolean)\n .map((part) => part.split('=')[0]?.trim())\n .filter((name): name is string => Boolean(name));\n}\n\nfunction getPathCandidates(pathname: string): string[] {\n const normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;\n const segments = normalized.split('/').filter(Boolean);\n const paths = new Set<string>(['/']);\n\n let current = '';\n for (const segment of segments) {\n current += `/${segment}`;\n paths.add(current);\n }\n\n return [...paths];\n}\n\nfunction resolveLogoutTargetUrl(request: NextRequest, config: AuthKitConfig): URL {\n const origin = request.cookies.get('auth_origin')?.value ?? config.appUrl ?? new URL(request.url).origin;\n const logoutRedirectPath = config.logoutRedirectPath ?? '/';\n return new URL(logoutRedirectPath, origin);\n}\n\nfunction clearCookieEverywhere(\n response: NextResponse,\n cookieName: string,\n secure: boolean,\n pathCandidates: string[],\n) {\n for (const path of pathCandidates) {\n response.cookies.set(cookieName, '', {\n path,\n httpOnly: true,\n sameSite: 'lax',\n secure,\n maxAge: 0,\n });\n }\n}\n\nexport function createLogoutHandler(config: AuthKitConfig) {\n return async function GET(request: NextRequest) {\n const secure = config.cookie?.secure === 'auto' ? isSecureRequest(request, config.appUrl) : Boolean(config.cookie?.secure);\n // 307 keeps same-path targets behaving like a reload instead of a cache-friendly rewrite.\n const targetUrl = resolveLogoutTargetUrl(request, config);\n const response = NextResponse.redirect(targetUrl, 307);\n response.headers.set('Clear-Site-Data', '\"cookies\"');\n const cookieNames = getCookieNamesFromHeader(request.headers.get('cookie'));\n const pathCandidates = getPathCandidates(request.nextUrl.pathname);\n\n for (const cookieName of cookieNames) {\n clearCookieEverywhere(response, cookieName, secure, pathCandidates);\n }\n clearCookieEverywhere(response, 'oauth_state', secure, pathCandidates);\n clearCookieEverywhere(response, 'auth_origin', secure, pathCandidates);\n clearCookieEverywhere(response, 'auth_redirect', secure, pathCandidates);\n clearAuthRedirectCookie(response, secure);\n clearPublicOriginCookie(response, secure);\n\n return response;\n };\n}\n","import NextAuth from 'next-auth';\nimport type { NextAuthOptions, Session } from 'next-auth';\nimport type { JWT } from 'next-auth/jwt';\nimport type { AuthBusinessAdapter, AuthKitConfig, AuthPersistenceAdapter, AuthUser } from '../types';\nimport { normalizeAuthKitConfig } from '../core/config';\nimport { decodeSessionToken, encodeSessionToken } from '../core/session-token';\nimport { isGlobalAdminEmail } from '../core/admin';\n\nexport interface NextAuthRouteOptions {\n config: AuthKitConfig;\n adapter?: AuthBusinessAdapter;\n persistence?: AuthPersistenceAdapter;\n providers?: NextAuthOptions['providers'];\n}\n\nexport interface AuthTokenPayload extends JWT {\n id?: string;\n name?: string;\n email?: string;\n picture?: string | null;\n userId?: string;\n accessToken?: string;\n expiresAt?: number;\n tokenBalance?: number;\n isVip?: boolean;\n isAdmin?: boolean;\n}\n\nexport interface AuthSessionUser {\n id?: string;\n isAdmin?: boolean;\n tokenBalance?: number;\n isVip?: boolean;\n}\n\nexport interface AuthSession extends Session {\n accessToken?: string;\n expiresAt?: number;\n user?: AuthSessionUser & NonNullable<Session['user']>;\n}\n\nfunction resolveAuthUserFromToken(token: AuthTokenPayload, adapter?: AuthBusinessAdapter): AuthUser {\n const email = typeof token.email === 'string' ? token.email : null;\n return {\n id: token.userId || token.sub || token.id || email || 'casdoor-user',\n name: typeof token.name === 'string' ? token.name : null,\n email,\n image: typeof token.picture === 'string' ? token.picture : null,\n isAdmin: Boolean(token.isAdmin) || Boolean(adapter?.isAdminEmail?.(email)) || isGlobalAdminEmail(email),\n tokenBalance: Number(token.tokenBalance ?? 2580),\n isVip: Boolean(token.isVip ?? true),\n };\n}\n\nexport function createNextAuthOptions(options: NextAuthRouteOptions): NextAuthOptions {\n const normalized = normalizeAuthKitConfig(options.config);\n\n return {\n providers: options.providers ?? [],\n session: {\n strategy: 'jwt',\n },\n jwt: {\n encode: encodeSessionToken,\n decode: decodeSessionToken,\n },\n pages: {\n signIn: '/login',\n error: '/callback/error',\n },\n callbacks: {\n async jwt({ token, account, profile }) {\n const typedToken = token as AuthTokenPayload;\n\n if (account) {\n typedToken.accessToken = account.access_token;\n typedToken.expiresAt = account.expires_at ? account.expires_at * 1000 : undefined;\n }\n\n if (profile && typeof profile === 'object') {\n const typedProfile = profile as Partial<AuthUser> & {\n sub?: string;\n id?: string;\n picture?: string;\n };\n\n typedToken.userId = typedProfile.id || typedProfile.sub || typedToken.userId;\n typedToken.name = typedProfile.name || typedToken.name;\n typedToken.email = typedProfile.email || typedToken.email;\n typedToken.picture = typedProfile.image || typedProfile.picture || typedToken.picture;\n typedToken.isAdmin = Boolean(typedProfile.isAdmin ?? typedToken.isAdmin);\n typedToken.tokenBalance = typedProfile.tokenBalance ?? typedToken.tokenBalance ?? 2580;\n typedToken.isVip = typedProfile.isVip ?? typedToken.isVip ?? true;\n }\n\n return typedToken;\n },\n async session({ session, token }) {\n const typedSession = session as AuthSession;\n const typedToken = token as AuthTokenPayload;\n const tokenUserId = typedToken.userId || typedToken.sub || typedToken.id || '';\n const tokenEmail = typeof typedToken.email === 'string' ? typedToken.email : null;\n const persistedUser = options.persistence?.findAuthUser\n ? await options.persistence.findAuthUser({ id: tokenUserId || undefined, email: tokenEmail })\n : null;\n const resolvedUser = persistedUser ?? resolveAuthUserFromToken(typedToken, options.adapter);\n\n if (typedSession.user) {\n typedSession.user.id = resolvedUser.id;\n typedSession.user.isAdmin = resolvedUser.isAdmin;\n typedSession.user.tokenBalance = resolvedUser.tokenBalance;\n typedSession.user.isVip = resolvedUser.isVip;\n }\n\n typedSession.accessToken = typedToken.accessToken;\n typedSession.expiresAt = typedToken.expiresAt;\n typedSession.user = {\n ...(typedSession.user || {}),\n name: typedSession.user?.name || resolvedUser.name,\n email: typedSession.user?.email || resolvedUser.email,\n image: typedSession.user?.image || resolvedUser.image,\n id: resolvedUser.id,\n isAdmin: resolvedUser.isAdmin,\n tokenBalance: resolvedUser.tokenBalance,\n isVip: resolvedUser.isVip,\n };\n\n return typedSession;\n },\n },\n events: {\n async signOut({ token }) {\n const typedToken = token as AuthTokenPayload | null;\n if (!typedToken?.accessToken || !normalized.appUrl) {\n return;\n }\n\n try {\n await fetch(new URL('/api/casdoor/logout', normalized.appUrl).toString(), {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${typedToken.accessToken}`,\n },\n });\n } catch {\n // ignored\n }\n },\n },\n secret: normalized.nextauthSecret,\n };\n}\n\nexport function createNextAuthRouteHandler(options: NextAuthRouteOptions) {\n const handler = NextAuth(createNextAuthOptions(options));\n return {\n GET: handler,\n POST: handler,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAIO,SAAS,wBAAwB,QAAuB;AAC7D,SAAO,OAAO,YAAyB,yBAAyB,SAAS,MAAM;AACjF;;;ACFO,SAAS,yBAAyB,QAAuB;AAC9D,SAAO,OAAO,YAAyB,0BAA0B,SAAS,MAAM;AAClF;;;ACFO,SAAS,4BAA4B,QAAuB;AACjE,SAAO,OAAO,YAAyB,6BAA6B,SAAS,MAAM;AACrF;;;ACNA,SAAS,oBAAsC;AAM/C,SAAS,yBAAyB,cAAuC;AACvE,MAAI,CAAC,cAAc;AACjB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,aACJ,MAAM,GAAG,EACT,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,OAAO,OAAO,EACd,IAAI,CAAC,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,EACxC,OAAO,CAAC,SAAyB,QAAQ,IAAI,CAAC;AACnD;AAEA,SAAS,kBAAkB,UAA4B;AACrD,QAAM,aAAa,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI,QAAQ;AACrE,QAAM,WAAW,WAAW,MAAM,GAAG,EAAE,OAAO,OAAO;AACrD,QAAM,QAAQ,oBAAI,IAAY,CAAC,GAAG,CAAC;AAEnC,MAAI,UAAU;AACd,aAAW,WAAW,UAAU;AAC9B,eAAW,IAAI,OAAO;AACtB,UAAM,IAAI,OAAO;AAAA,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,QAAQ;AAAA,YACR,SAAS;AAAA,cACP,eAAe,UAAU,WAAW,WAAW;AAAA,YACjD;AAAA,UACF,CAAC;AAAA,QACH,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,IACA,QAAQ,WAAW;AAAA,EACrB;AACF;AAEO,SAAS,2BAA2B,SAA+B;AACxE,QAAM,UAAU,SAAS,sBAAsB,OAAO,CAAC;AACvD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AACF;","names":[]}
@@ -1,20 +0,0 @@
1
- // src/core/redirect.ts
2
- function buildAuthJumpHref(kind, redirect, basePath = "/auth") {
3
- const normalizedBasePath = basePath ? basePath.startsWith("/") ? basePath : "/" + basePath : "";
4
- const targetPath = (normalizedBasePath + "/" + kind).replace(/\/+/g, "/");
5
- const url = new URL(targetPath, "http://localhost");
6
- if (redirect) {
7
- url.searchParams.set("redirect", redirect);
8
- }
9
- return url.pathname + url.search;
10
- }
11
- function resolvePostLoginRedirect(user, fallback = "/") {
12
- if (user.isAdmin) return "/admin";
13
- return fallback;
14
- }
15
-
16
- export {
17
- buildAuthJumpHref,
18
- resolvePostLoginRedirect
19
- };
20
- //# sourceMappingURL=chunk-T2M5MVPE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/redirect.ts"],"sourcesContent":["import type { AuthUser } from '../types';\n\nexport function buildAuthJumpHref(kind: 'login' | 'signup', redirect?: string, basePath = '/auth'): string {\n const normalizedBasePath = basePath ? (basePath.startsWith('/') ? basePath : '/' + basePath) : '';\n const targetPath = (normalizedBasePath + '/' + kind).replace(/\\/+/g, '/');\n const url = new URL(targetPath, 'http://localhost');\n\n if (redirect) {\n url.searchParams.set('redirect', redirect);\n }\n\n return url.pathname + url.search;\n}\n\nexport function resolvePostLoginRedirect(user: AuthUser, fallback = '/'): string {\n if (user.isAdmin) return '/admin';\n return fallback;\n}\n"],"mappings":";AAEO,SAAS,kBAAkB,MAA0B,UAAmB,WAAW,SAAiB;AACzG,QAAM,qBAAqB,WAAY,SAAS,WAAW,GAAG,IAAI,WAAW,MAAM,WAAY;AAC/F,QAAM,cAAc,qBAAqB,MAAM,MAAM,QAAQ,QAAQ,GAAG;AACxE,QAAM,MAAM,IAAI,IAAI,YAAY,kBAAkB;AAElD,MAAI,UAAU;AACZ,QAAI,aAAa,IAAI,YAAY,QAAQ;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAW,IAAI;AAC5B;AAEO,SAAS,yBAAyB,MAAgB,WAAW,KAAa;AAC/E,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO;AACT;","names":[]}