better-auth-studio 1.0.20-beta.3 → 1.0.20-beta.5
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/auth-adapter.d.ts.map +1 -1
- package/dist/auth-adapter.js +134 -54
- package/dist/auth-adapter.js.map +1 -1
- package/dist/cli.js +17 -16
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +43 -33
- package/dist/config.js.map +1 -1
- package/dist/data.d.ts +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +19 -19
- package/dist/data.js.map +1 -1
- package/dist/geo-service.d.ts.map +1 -1
- package/dist/geo-service.js +107 -21
- package/dist/geo-service.js.map +1 -1
- package/dist/routes.d.ts +3 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +260 -234
- package/dist/routes.js.map +1 -1
- package/dist/studio.d.ts +1 -1
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +8 -8
- package/dist/studio.js.map +1 -1
- package/package.json +12 -6
- package/public/assets/{main-DsrV340F.js → main-SNev5eZ4.js} +11 -11
- package/public/index.html +1 -1
package/dist/routes.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
import { getAuthAdapter, createMockUser, createMockSession, createMockAccount, createMockVerification } from './auth-adapter.js';
|
|
4
|
-
import { resolveIPLocation, initializeGeoService, setGeoDbPath } from './geo-service.js';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
5
3
|
import { createJiti } from 'jiti';
|
|
6
|
-
import {
|
|
7
|
-
import { join, dirname } from 'path';
|
|
4
|
+
import { dirname, join } from 'path';
|
|
8
5
|
import { pathToFileURL } from 'url';
|
|
6
|
+
import { createMockAccount, createMockSession, createMockUser, createMockVerification, getAuthAdapter, } from './auth-adapter.js';
|
|
7
|
+
import { getAuthData } from './data.js';
|
|
8
|
+
import { initializeGeoService, resolveIPLocation, setGeoDbPath } from './geo-service.js';
|
|
9
9
|
function resolveModuleWithExtensions(id, parent) {
|
|
10
10
|
if (!id.startsWith('./') && !id.startsWith('../')) {
|
|
11
11
|
return id;
|
|
@@ -55,7 +55,7 @@ export async function safeImportAuthConfig(authConfigPath) {
|
|
|
55
55
|
join(authConfigDir, importName, 'index.ts'),
|
|
56
56
|
join(authConfigDir, importName, 'index.js'),
|
|
57
57
|
join(authConfigDir, importName, 'index.mjs'),
|
|
58
|
-
join(authConfigDir, importName, 'index.cjs')
|
|
58
|
+
join(authConfigDir, importName, 'index.cjs'),
|
|
59
59
|
];
|
|
60
60
|
for (const path of possiblePaths) {
|
|
61
61
|
if (existsSync(path)) {
|
|
@@ -69,7 +69,7 @@ export async function safeImportAuthConfig(authConfigPath) {
|
|
|
69
69
|
fsCache: true,
|
|
70
70
|
moduleCache: true,
|
|
71
71
|
interopDefault: true,
|
|
72
|
-
alias: aliases
|
|
72
|
+
alias: aliases,
|
|
73
73
|
});
|
|
74
74
|
try {
|
|
75
75
|
return await jiti.import(authConfigPath);
|
|
@@ -79,9 +79,9 @@ export async function safeImportAuthConfig(authConfigPath) {
|
|
|
79
79
|
return {
|
|
80
80
|
auth: {
|
|
81
81
|
options: {
|
|
82
|
-
_content: content
|
|
83
|
-
}
|
|
84
|
-
}
|
|
82
|
+
_content: content,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -169,7 +169,7 @@ async function findAuthConfigPath() {
|
|
|
169
169
|
'src/auth.js',
|
|
170
170
|
'src/auth.ts',
|
|
171
171
|
'lib/auth.js',
|
|
172
|
-
'lib/auth.ts'
|
|
172
|
+
'lib/auth.ts',
|
|
173
173
|
];
|
|
174
174
|
for (const path of possiblePaths) {
|
|
175
175
|
const fullPath = join(process.cwd(), path);
|
|
@@ -179,15 +179,13 @@ async function findAuthConfigPath() {
|
|
|
179
179
|
}
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
182
|
+
// @ts-nocheck
|
|
182
183
|
export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
183
184
|
const router = Router();
|
|
184
|
-
// Set geo database path if provided
|
|
185
185
|
if (geoDbPath) {
|
|
186
186
|
setGeoDbPath(geoDbPath);
|
|
187
187
|
}
|
|
188
|
-
// Initialize Geo service
|
|
189
188
|
initializeGeoService().catch(console.error);
|
|
190
|
-
// Store the config path for use in adapter functions
|
|
191
189
|
const getAuthAdapterWithConfig = () => getAuthAdapter(configPath);
|
|
192
190
|
router.get('/api/health', (req, res) => {
|
|
193
191
|
const uptime = process.uptime();
|
|
@@ -206,11 +204,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
206
204
|
memory: {
|
|
207
205
|
used: Math.round(process.memoryUsage().heapUsed / 1024 / 1024),
|
|
208
206
|
total: Math.round(process.memoryUsage().heapTotal / 1024 / 1024),
|
|
209
|
-
external: Math.round(process.memoryUsage().external / 1024 / 1024)
|
|
207
|
+
external: Math.round(process.memoryUsage().external / 1024 / 1024),
|
|
210
208
|
},
|
|
211
209
|
pid: process.pid,
|
|
212
|
-
cwd: process.cwd()
|
|
213
|
-
}
|
|
210
|
+
cwd: process.cwd(),
|
|
211
|
+
},
|
|
214
212
|
});
|
|
215
213
|
});
|
|
216
214
|
// IP Geolocation endpoint
|
|
@@ -220,26 +218,26 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
220
218
|
if (!ipAddress) {
|
|
221
219
|
return res.status(400).json({
|
|
222
220
|
success: false,
|
|
223
|
-
error: 'IP address is required'
|
|
221
|
+
error: 'IP address is required',
|
|
224
222
|
});
|
|
225
223
|
}
|
|
226
224
|
const location = resolveIPLocation(ipAddress);
|
|
227
225
|
if (!location) {
|
|
228
226
|
return res.status(404).json({
|
|
229
227
|
success: false,
|
|
230
|
-
error: 'Location not found for IP address'
|
|
228
|
+
error: 'Location not found for IP address',
|
|
231
229
|
});
|
|
232
230
|
}
|
|
233
231
|
res.json({
|
|
234
232
|
success: true,
|
|
235
|
-
location
|
|
233
|
+
location,
|
|
236
234
|
});
|
|
237
235
|
}
|
|
238
236
|
catch (error) {
|
|
239
237
|
console.error('Error resolving IP location:', error);
|
|
240
238
|
res.status(500).json({
|
|
241
239
|
success: false,
|
|
242
|
-
error: 'Failed to resolve IP location'
|
|
240
|
+
error: 'Failed to resolve IP location',
|
|
243
241
|
});
|
|
244
242
|
}
|
|
245
243
|
});
|
|
@@ -275,13 +273,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
275
273
|
dialect: authConfig.database?.dialect || authConfig.database?.provider || 'unknown',
|
|
276
274
|
casing: authConfig.database?.casing || 'camel',
|
|
277
275
|
debugLogs: authConfig.database?.debugLogs || false,
|
|
278
|
-
url: authConfig.database?.url
|
|
276
|
+
url: authConfig.database?.url,
|
|
279
277
|
},
|
|
280
278
|
emailVerification: {
|
|
281
279
|
sendOnSignUp: authConfig.emailVerification?.sendOnSignUp || false,
|
|
282
280
|
sendOnSignIn: authConfig.emailVerification?.sendOnSignIn || false,
|
|
283
281
|
autoSignInAfterVerification: authConfig.emailVerification?.autoSignInAfterVerification || false,
|
|
284
|
-
expiresIn: authConfig.emailVerification?.expiresIn || 3600
|
|
282
|
+
expiresIn: authConfig.emailVerification?.expiresIn || 3600,
|
|
285
283
|
},
|
|
286
284
|
emailAndPassword: {
|
|
287
285
|
enabled: authConfig.emailAndPassword?.enabled ?? false,
|
|
@@ -291,26 +289,26 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
291
289
|
minPasswordLength: authConfig.emailAndPassword?.minPasswordLength ?? 8,
|
|
292
290
|
resetPasswordTokenExpiresIn: authConfig.emailAndPassword?.resetPasswordTokenExpiresIn ?? 3600,
|
|
293
291
|
autoSignIn: authConfig.emailAndPassword?.autoSignIn ?? true, // defaults to true
|
|
294
|
-
revokeSessionsOnPasswordReset: authConfig.emailAndPassword?.revokeSessionsOnPasswordReset ?? false
|
|
292
|
+
revokeSessionsOnPasswordReset: authConfig.emailAndPassword?.revokeSessionsOnPasswordReset ?? false,
|
|
295
293
|
},
|
|
296
|
-
socialProviders: authConfig.socialProviders
|
|
297
|
-
Object.entries(authConfig.socialProviders).map(([provider, config]) => ({
|
|
294
|
+
socialProviders: authConfig.socialProviders
|
|
295
|
+
? Object.entries(authConfig.socialProviders).map(([provider, config]) => ({
|
|
298
296
|
type: provider,
|
|
299
297
|
clientId: config.clientId,
|
|
300
298
|
clientSecret: config.clientSecret,
|
|
301
299
|
redirectUri: config.redirectUri,
|
|
302
|
-
...config
|
|
303
|
-
}))
|
|
304
|
-
|
|
300
|
+
...config,
|
|
301
|
+
}))
|
|
302
|
+
: authConfig.providers || [],
|
|
305
303
|
user: {
|
|
306
304
|
modelName: authConfig.user?.modelName || 'user',
|
|
307
305
|
changeEmail: {
|
|
308
|
-
enabled: authConfig.user?.changeEmail?.enabled || false
|
|
306
|
+
enabled: authConfig.user?.changeEmail?.enabled || false,
|
|
309
307
|
},
|
|
310
308
|
deleteUser: {
|
|
311
309
|
enabled: authConfig.user?.deleteUser?.enabled || false,
|
|
312
|
-
deleteTokenExpiresIn: authConfig.user?.deleteUser?.deleteTokenExpiresIn || 86400
|
|
313
|
-
}
|
|
310
|
+
deleteTokenExpiresIn: authConfig.user?.deleteUser?.deleteTokenExpiresIn || 86400,
|
|
311
|
+
},
|
|
314
312
|
},
|
|
315
313
|
session: {
|
|
316
314
|
modelName: authConfig.session?.modelName || 'session',
|
|
@@ -321,9 +319,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
321
319
|
preserveSessionInDatabase: authConfig.session?.preserveSessionInDatabase || false,
|
|
322
320
|
cookieCache: {
|
|
323
321
|
enabled: authConfig.session?.cookieCache?.enabled || false,
|
|
324
|
-
maxAge: authConfig.session?.cookieCache?.maxAge || 300
|
|
322
|
+
maxAge: authConfig.session?.cookieCache?.maxAge || 300,
|
|
325
323
|
},
|
|
326
|
-
freshAge: authConfig.session?.freshAge || 86400
|
|
324
|
+
freshAge: authConfig.session?.freshAge || 86400,
|
|
327
325
|
},
|
|
328
326
|
account: {
|
|
329
327
|
modelName: authConfig.account?.modelName || 'account',
|
|
@@ -333,13 +331,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
333
331
|
trustedProviders: authConfig.account?.accountLinking?.trustedProviders || [],
|
|
334
332
|
allowDifferentEmails: authConfig.account?.accountLinking?.allowDifferentEmails || false,
|
|
335
333
|
allowUnlinkingAll: authConfig.account?.accountLinking?.allowUnlinkingAll || false,
|
|
336
|
-
updateUserInfoOnLink: authConfig.account?.accountLinking?.updateUserInfoOnLink || false
|
|
334
|
+
updateUserInfoOnLink: authConfig.account?.accountLinking?.updateUserInfoOnLink || false,
|
|
337
335
|
},
|
|
338
|
-
encryptOAuthTokens: authConfig.account?.encryptOAuthTokens || false
|
|
336
|
+
encryptOAuthTokens: authConfig.account?.encryptOAuthTokens || false,
|
|
339
337
|
},
|
|
340
338
|
verification: {
|
|
341
339
|
modelName: authConfig.verification?.modelName || 'verification',
|
|
342
|
-
disableCleanup: authConfig.verification?.disableCleanup || false
|
|
340
|
+
disableCleanup: authConfig.verification?.disableCleanup || false,
|
|
343
341
|
},
|
|
344
342
|
trustedOrigins: Array.isArray(authConfig.trustedOrigins) ? authConfig.trustedOrigins : [],
|
|
345
343
|
rateLimit: {
|
|
@@ -347,39 +345,39 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
347
345
|
window: authConfig.rateLimit?.window || 10,
|
|
348
346
|
max: authConfig.rateLimit?.max || 100,
|
|
349
347
|
storage: authConfig.rateLimit?.storage || 'memory',
|
|
350
|
-
modelName: authConfig.rateLimit?.modelName || 'rateLimit'
|
|
348
|
+
modelName: authConfig.rateLimit?.modelName || 'rateLimit',
|
|
351
349
|
},
|
|
352
350
|
advanced: {
|
|
353
351
|
ipAddress: {
|
|
354
352
|
ipAddressHeaders: authConfig.advanced?.ipAddress?.ipAddressHeaders || [],
|
|
355
|
-
disableIpTracking: authConfig.advanced?.ipAddress?.disableIpTracking || false
|
|
353
|
+
disableIpTracking: authConfig.advanced?.ipAddress?.disableIpTracking || false,
|
|
356
354
|
},
|
|
357
355
|
useSecureCookies: authConfig.advanced?.useSecureCookies || false,
|
|
358
356
|
disableCSRFCheck: authConfig.advanced?.disableCSRFCheck || false,
|
|
359
357
|
crossSubDomainCookies: {
|
|
360
358
|
enabled: authConfig.advanced?.crossSubDomainCookies?.enabled || false,
|
|
361
359
|
additionalCookies: authConfig.advanced?.crossSubDomainCookies?.additionalCookies || [],
|
|
362
|
-
domain: authConfig.advanced?.crossSubDomainCookies?.domain
|
|
360
|
+
domain: authConfig.advanced?.crossSubDomainCookies?.domain,
|
|
363
361
|
},
|
|
364
362
|
cookies: authConfig.advanced?.cookies || {},
|
|
365
363
|
defaultCookieAttributes: authConfig.advanced?.defaultCookieAttributes || {},
|
|
366
364
|
cookiePrefix: authConfig.advanced?.cookiePrefix,
|
|
367
365
|
database: {
|
|
368
366
|
defaultFindManyLimit: authConfig.advanced?.database?.defaultFindManyLimit || 100,
|
|
369
|
-
useNumberId: authConfig.advanced?.database?.useNumberId || false
|
|
370
|
-
}
|
|
367
|
+
useNumberId: authConfig.advanced?.database?.useNumberId || false,
|
|
368
|
+
},
|
|
371
369
|
},
|
|
372
370
|
disabledPaths: authConfig.disabledPaths || [],
|
|
373
371
|
telemetry: {
|
|
374
372
|
enabled: authConfig.telemetry?.enabled ?? false,
|
|
375
|
-
debug: authConfig.telemetry?.debug || false
|
|
373
|
+
debug: authConfig.telemetry?.debug || false,
|
|
376
374
|
},
|
|
377
375
|
studio: {
|
|
378
376
|
version: '1.0.0',
|
|
379
377
|
nodeVersion: process.version,
|
|
380
378
|
platform: process.platform,
|
|
381
|
-
uptime: process.uptime()
|
|
382
|
-
}
|
|
379
|
+
uptime: process.uptime(),
|
|
380
|
+
},
|
|
383
381
|
};
|
|
384
382
|
res.json(config);
|
|
385
383
|
});
|
|
@@ -432,7 +430,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
432
430
|
res.json({
|
|
433
431
|
users: userCount,
|
|
434
432
|
sessions: sessionCount,
|
|
435
|
-
organizations: organizationCount
|
|
433
|
+
organizations: organizationCount,
|
|
436
434
|
});
|
|
437
435
|
}
|
|
438
436
|
catch (error) {
|
|
@@ -469,7 +467,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
469
467
|
const users = await adapter.findMany({
|
|
470
468
|
model: 'user',
|
|
471
469
|
where: [{ field: 'id', value: userId }],
|
|
472
|
-
limit: 1
|
|
470
|
+
limit: 1,
|
|
473
471
|
});
|
|
474
472
|
const user = users && users.length > 0 ? users[0] : null;
|
|
475
473
|
if (!user) {
|
|
@@ -493,7 +491,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
493
491
|
const user = await adapter.update({
|
|
494
492
|
model: 'user',
|
|
495
493
|
where: [{ field: 'id', value: userId }],
|
|
496
|
-
update: { name, email }
|
|
494
|
+
update: { name, email },
|
|
497
495
|
});
|
|
498
496
|
res.json({ success: true, user });
|
|
499
497
|
}
|
|
@@ -526,27 +524,29 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
526
524
|
}
|
|
527
525
|
const [memberships, organizations] = await Promise.all([
|
|
528
526
|
adapter.findMany({ model: 'member', limit: 10000 }),
|
|
529
|
-
adapter.findMany({ model: 'organization', limit: 10000 })
|
|
527
|
+
adapter.findMany({ model: 'organization', limit: 10000 }),
|
|
530
528
|
]);
|
|
531
529
|
const userMemberships = memberships.filter((membership) => membership.userId === userId);
|
|
532
530
|
const formattedMemberships = userMemberships.map((membership) => {
|
|
533
531
|
const organization = organizations.find((org) => org.id === membership.organizationId);
|
|
534
532
|
return {
|
|
535
533
|
id: membership.id,
|
|
536
|
-
organization: organization
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
534
|
+
organization: organization
|
|
535
|
+
? {
|
|
536
|
+
id: organization.id,
|
|
537
|
+
name: organization.name || 'Unknown Organization',
|
|
538
|
+
slug: organization.slug || 'unknown',
|
|
539
|
+
image: organization.image,
|
|
540
|
+
createdAt: organization.createdAt,
|
|
541
|
+
}
|
|
542
|
+
: {
|
|
543
|
+
id: membership.organizationId,
|
|
544
|
+
name: 'Unknown Organization',
|
|
545
|
+
slug: 'unknown',
|
|
546
|
+
createdAt: membership.createdAt,
|
|
547
|
+
},
|
|
548
548
|
role: membership.role || 'member',
|
|
549
|
-
joinedAt: membership.createdAt
|
|
549
|
+
joinedAt: membership.createdAt,
|
|
550
550
|
};
|
|
551
551
|
});
|
|
552
552
|
res.json({ memberships: formattedMemberships });
|
|
@@ -566,27 +566,33 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
566
566
|
const [memberships, teams, organizations] = await Promise.all([
|
|
567
567
|
adapter.findMany({ model: 'teamMember', limit: 10000 }),
|
|
568
568
|
adapter.findMany({ model: 'team', limit: 10000 }),
|
|
569
|
-
adapter.findMany({ model: 'organization', limit: 10000 })
|
|
569
|
+
adapter.findMany({ model: 'organization', limit: 10000 }),
|
|
570
570
|
]);
|
|
571
571
|
const userMemberships = memberships.filter((membership) => membership.userId === userId);
|
|
572
572
|
const formattedMemberships = userMemberships.map((membership) => {
|
|
573
573
|
const team = teams.find((t) => t.id === membership.teamId);
|
|
574
|
-
const organization = team
|
|
574
|
+
const organization = team
|
|
575
|
+
? organizations.find((org) => org.id === team.organizationId)
|
|
576
|
+
: null;
|
|
575
577
|
return {
|
|
576
578
|
id: membership.id,
|
|
577
|
-
team: team
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
579
|
+
team: team
|
|
580
|
+
? {
|
|
581
|
+
id: team.id,
|
|
582
|
+
name: team.name || 'Unknown Team',
|
|
583
|
+
organizationId: team.organizationId,
|
|
584
|
+
organizationName: organization
|
|
585
|
+
? organization.name || 'Unknown Organization'
|
|
586
|
+
: 'Unknown Organization',
|
|
587
|
+
}
|
|
588
|
+
: {
|
|
589
|
+
id: membership.teamId,
|
|
590
|
+
name: 'Unknown Team',
|
|
591
|
+
organizationId: 'unknown',
|
|
592
|
+
organizationName: 'Unknown Organization',
|
|
593
|
+
},
|
|
588
594
|
role: membership.role || 'member',
|
|
589
|
-
joinedAt: membership.createdAt
|
|
595
|
+
joinedAt: membership.createdAt,
|
|
590
596
|
};
|
|
591
597
|
});
|
|
592
598
|
res.json({ memberships: formattedMemberships });
|
|
@@ -636,7 +642,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
636
642
|
const user = await adapter.update({
|
|
637
643
|
model: 'user',
|
|
638
644
|
id: userId,
|
|
639
|
-
data: { banned: true }
|
|
645
|
+
data: { banned: true },
|
|
640
646
|
});
|
|
641
647
|
res.json({ success: true, user });
|
|
642
648
|
}
|
|
@@ -654,7 +660,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
654
660
|
}
|
|
655
661
|
const sessions = await adapter.findMany({
|
|
656
662
|
model: 'session',
|
|
657
|
-
limit: 10000
|
|
663
|
+
limit: 10000,
|
|
658
664
|
});
|
|
659
665
|
const userSessions = sessions.filter((session) => session.userId === userId);
|
|
660
666
|
const formattedSessions = userSessions.map((session) => ({
|
|
@@ -666,7 +672,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
666
672
|
activeOrganizationId: session.activeOrganizationId,
|
|
667
673
|
activeTeamId: session.activeTeamId,
|
|
668
674
|
createdAt: session.createdAt,
|
|
669
|
-
updatedAt: session.updatedAt
|
|
675
|
+
updatedAt: session.updatedAt,
|
|
670
676
|
}));
|
|
671
677
|
res.json({ sessions: formattedSessions });
|
|
672
678
|
}
|
|
@@ -700,7 +706,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
700
706
|
const teams = await adapter.findMany({
|
|
701
707
|
model: 'team',
|
|
702
708
|
where: [{ field: 'id', value: teamId }],
|
|
703
|
-
limit: 1
|
|
709
|
+
limit: 1,
|
|
704
710
|
});
|
|
705
711
|
const team = teams && teams.length > 0 ? teams[0] : null;
|
|
706
712
|
if (!team) {
|
|
@@ -712,7 +718,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
712
718
|
const orgs = await adapter.findMany({
|
|
713
719
|
model: 'organization',
|
|
714
720
|
where: [{ field: 'id', value: team.organizationId }],
|
|
715
|
-
limit: 1
|
|
721
|
+
limit: 1,
|
|
716
722
|
});
|
|
717
723
|
organization = orgs && orgs.length > 0 ? orgs[0] : null;
|
|
718
724
|
}
|
|
@@ -727,10 +733,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
727
733
|
createdAt: team.createdAt,
|
|
728
734
|
updatedAt: team.updatedAt,
|
|
729
735
|
memberCount: team.memberCount || 0,
|
|
730
|
-
organization: organization
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
736
|
+
organization: organization
|
|
737
|
+
? {
|
|
738
|
+
id: organization.id,
|
|
739
|
+
name: organization.name,
|
|
740
|
+
}
|
|
741
|
+
: null,
|
|
734
742
|
};
|
|
735
743
|
res.json({ success: true, team: transformedTeam });
|
|
736
744
|
}
|
|
@@ -749,7 +757,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
749
757
|
const organizations = await adapter.findMany({
|
|
750
758
|
model: 'organization',
|
|
751
759
|
where: [{ field: 'id', value: orgId }],
|
|
752
|
-
limit: 1
|
|
760
|
+
limit: 1,
|
|
753
761
|
});
|
|
754
762
|
const organization = organizations && organizations.length > 0 ? organizations[0] : null;
|
|
755
763
|
if (!organization) {
|
|
@@ -855,12 +863,14 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
855
863
|
});
|
|
856
864
|
router.get('/api/plugins', async (req, res) => {
|
|
857
865
|
try {
|
|
858
|
-
const authConfigPath = configPath
|
|
866
|
+
const authConfigPath = configPath
|
|
867
|
+
? join(process.cwd(), configPath)
|
|
868
|
+
: await findAuthConfigPath();
|
|
859
869
|
if (!authConfigPath) {
|
|
860
870
|
return res.json({
|
|
861
871
|
plugins: [],
|
|
862
872
|
error: 'No auth config found',
|
|
863
|
-
configPath: null
|
|
873
|
+
configPath: null,
|
|
864
874
|
});
|
|
865
875
|
}
|
|
866
876
|
try {
|
|
@@ -875,9 +885,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
875
885
|
auth: {
|
|
876
886
|
options: {
|
|
877
887
|
_content: content,
|
|
878
|
-
plugins: []
|
|
879
|
-
}
|
|
880
|
-
}
|
|
888
|
+
plugins: [],
|
|
889
|
+
},
|
|
890
|
+
},
|
|
881
891
|
};
|
|
882
892
|
}
|
|
883
893
|
const auth = authModule.auth || authModule.default;
|
|
@@ -885,7 +895,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
885
895
|
return res.json({
|
|
886
896
|
plugins: [],
|
|
887
897
|
error: 'No auth export found',
|
|
888
|
-
configPath: authConfigPath
|
|
898
|
+
configPath: authConfigPath,
|
|
889
899
|
});
|
|
890
900
|
}
|
|
891
901
|
const plugins = auth.options?.plugins || [];
|
|
@@ -893,12 +903,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
893
903
|
id: plugin.id,
|
|
894
904
|
name: plugin.name || plugin.id,
|
|
895
905
|
description: plugin.description || `${plugin.id} plugin for Better Auth`,
|
|
896
|
-
enabled: true
|
|
906
|
+
enabled: true,
|
|
897
907
|
}));
|
|
898
908
|
res.json({
|
|
899
909
|
plugins: pluginInfo,
|
|
900
910
|
configPath: authConfigPath,
|
|
901
|
-
totalPlugins: pluginInfo.length
|
|
911
|
+
totalPlugins: pluginInfo.length,
|
|
902
912
|
});
|
|
903
913
|
}
|
|
904
914
|
catch (error) {
|
|
@@ -914,13 +924,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
914
924
|
name: plugin.name || plugin.id || 'unknown',
|
|
915
925
|
version: plugin.version || 'unknown',
|
|
916
926
|
description: plugin.description || `${plugin.id || 'unknown'} plugin for Better Auth`,
|
|
917
|
-
enabled: true
|
|
927
|
+
enabled: true,
|
|
918
928
|
}));
|
|
919
929
|
return res.json({
|
|
920
930
|
plugins: pluginInfo,
|
|
921
931
|
configPath: authConfigPath,
|
|
922
932
|
totalPlugins: pluginInfo.length,
|
|
923
|
-
fallback: true
|
|
933
|
+
fallback: true,
|
|
924
934
|
});
|
|
925
935
|
}
|
|
926
936
|
}
|
|
@@ -930,7 +940,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
930
940
|
res.json({
|
|
931
941
|
plugins: [],
|
|
932
942
|
error: 'Failed to load auth config - import failed and regex extraction unavailable',
|
|
933
|
-
configPath: authConfigPath
|
|
943
|
+
configPath: authConfigPath,
|
|
934
944
|
});
|
|
935
945
|
}
|
|
936
946
|
}
|
|
@@ -941,12 +951,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
941
951
|
});
|
|
942
952
|
router.get('/api/database/info', async (req, res) => {
|
|
943
953
|
try {
|
|
944
|
-
const authConfigPath = configPath || await findAuthConfigPath();
|
|
954
|
+
const authConfigPath = configPath || (await findAuthConfigPath());
|
|
945
955
|
if (!authConfigPath) {
|
|
946
956
|
return res.json({
|
|
947
957
|
database: null,
|
|
948
958
|
error: 'No auth config found',
|
|
949
|
-
configPath: null
|
|
959
|
+
configPath: null,
|
|
950
960
|
});
|
|
951
961
|
}
|
|
952
962
|
try {
|
|
@@ -956,13 +966,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
956
966
|
return res.json({
|
|
957
967
|
database: null,
|
|
958
968
|
error: 'No auth export found',
|
|
959
|
-
configPath: authConfigPath
|
|
969
|
+
configPath: authConfigPath,
|
|
960
970
|
});
|
|
961
971
|
}
|
|
962
972
|
const database = auth.options?.database;
|
|
963
973
|
res.json({
|
|
964
974
|
database: database,
|
|
965
|
-
configPath: authConfigPath
|
|
975
|
+
configPath: authConfigPath,
|
|
966
976
|
});
|
|
967
977
|
}
|
|
968
978
|
catch (error) {
|
|
@@ -976,7 +986,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
976
986
|
return res.json({
|
|
977
987
|
database: config.database,
|
|
978
988
|
configPath: authConfigPath,
|
|
979
|
-
fallback: true
|
|
989
|
+
fallback: true,
|
|
980
990
|
});
|
|
981
991
|
}
|
|
982
992
|
}
|
|
@@ -986,7 +996,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
986
996
|
res.json({
|
|
987
997
|
database: null,
|
|
988
998
|
error: 'Failed to load auth config - import failed and regex extraction unavailable',
|
|
989
|
-
configPath: authConfigPath
|
|
999
|
+
configPath: authConfigPath,
|
|
990
1000
|
});
|
|
991
1001
|
}
|
|
992
1002
|
}
|
|
@@ -997,12 +1007,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
997
1007
|
});
|
|
998
1008
|
router.get('/api/plugins/teams/status', async (req, res) => {
|
|
999
1009
|
try {
|
|
1000
|
-
const authConfigPath = configPath || await findAuthConfigPath();
|
|
1010
|
+
const authConfigPath = configPath || (await findAuthConfigPath());
|
|
1001
1011
|
if (!authConfigPath) {
|
|
1002
1012
|
return res.json({
|
|
1003
1013
|
enabled: false,
|
|
1004
1014
|
error: 'No auth config found',
|
|
1005
|
-
configPath: null
|
|
1015
|
+
configPath: null,
|
|
1006
1016
|
});
|
|
1007
1017
|
}
|
|
1008
1018
|
try {
|
|
@@ -1017,9 +1027,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1017
1027
|
auth: {
|
|
1018
1028
|
options: {
|
|
1019
1029
|
_content: content,
|
|
1020
|
-
plugins: []
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1030
|
+
plugins: [],
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1023
1033
|
};
|
|
1024
1034
|
}
|
|
1025
1035
|
const auth = authModule.auth || authModule.default;
|
|
@@ -1027,15 +1037,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1027
1037
|
return res.json({
|
|
1028
1038
|
enabled: false,
|
|
1029
1039
|
error: 'No auth export found',
|
|
1030
|
-
configPath: authConfigPath
|
|
1040
|
+
configPath: authConfigPath,
|
|
1031
1041
|
});
|
|
1032
1042
|
}
|
|
1033
|
-
const organizationPlugin = auth.options?.plugins?.find((plugin) => plugin.id ===
|
|
1043
|
+
const organizationPlugin = auth.options?.plugins?.find((plugin) => plugin.id === 'organization');
|
|
1034
1044
|
const teamsEnabled = organizationPlugin?.teams?.enabled === true;
|
|
1035
1045
|
res.json({
|
|
1036
1046
|
enabled: teamsEnabled,
|
|
1037
1047
|
configPath: authConfigPath,
|
|
1038
|
-
organizationPlugin: organizationPlugin || null
|
|
1048
|
+
organizationPlugin: organizationPlugin || null,
|
|
1039
1049
|
});
|
|
1040
1050
|
}
|
|
1041
1051
|
catch (error) {
|
|
@@ -1046,13 +1056,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1046
1056
|
const { extractBetterAuthConfig } = await import('./config');
|
|
1047
1057
|
const config = extractBetterAuthConfig(content);
|
|
1048
1058
|
if (config && config.plugins) {
|
|
1049
|
-
const organizationPlugin = config.plugins.find((plugin) => plugin.id ===
|
|
1059
|
+
const organizationPlugin = config.plugins.find((plugin) => plugin.id === 'organization');
|
|
1050
1060
|
const teamsEnabled = organizationPlugin?.teams?.enabled === true;
|
|
1051
1061
|
return res.json({
|
|
1052
1062
|
enabled: teamsEnabled,
|
|
1053
1063
|
configPath: authConfigPath,
|
|
1054
1064
|
organizationPlugin: organizationPlugin || null,
|
|
1055
|
-
fallback: true
|
|
1065
|
+
fallback: true,
|
|
1056
1066
|
});
|
|
1057
1067
|
}
|
|
1058
1068
|
}
|
|
@@ -1062,7 +1072,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1062
1072
|
res.json({
|
|
1063
1073
|
enabled: false,
|
|
1064
1074
|
error: 'Failed to load auth config - import failed and regex extraction unavailable',
|
|
1065
|
-
configPath: authConfigPath
|
|
1075
|
+
configPath: authConfigPath,
|
|
1066
1076
|
});
|
|
1067
1077
|
}
|
|
1068
1078
|
}
|
|
@@ -1081,7 +1091,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1081
1091
|
model: 'invitation',
|
|
1082
1092
|
where: [
|
|
1083
1093
|
{ field: 'organizationId', value: orgId },
|
|
1084
|
-
{ field: 'status', value: 'pending' }
|
|
1094
|
+
{ field: 'status', value: 'pending' },
|
|
1085
1095
|
],
|
|
1086
1096
|
});
|
|
1087
1097
|
const transformedInvitations = (invitations || []).map((invitation) => ({
|
|
@@ -1093,7 +1103,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1093
1103
|
teamId: invitation.teamId,
|
|
1094
1104
|
inviterId: invitation.inviterId,
|
|
1095
1105
|
expiresAt: invitation.expiresAt,
|
|
1096
|
-
createdAt: invitation.createdAt
|
|
1106
|
+
createdAt: invitation.createdAt,
|
|
1097
1107
|
}));
|
|
1098
1108
|
res.json({ success: true, invitations: transformedInvitations });
|
|
1099
1109
|
return;
|
|
@@ -1118,7 +1128,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1118
1128
|
const members = await adapter.findMany({
|
|
1119
1129
|
model: 'member',
|
|
1120
1130
|
where: [{ field: 'organizationId', value: orgId }],
|
|
1121
|
-
limit: 10000
|
|
1131
|
+
limit: 10000,
|
|
1122
1132
|
});
|
|
1123
1133
|
const membersWithUsers = await Promise.all((members || []).map(async (member) => {
|
|
1124
1134
|
try {
|
|
@@ -1126,7 +1136,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1126
1136
|
const users = await adapter.findMany({
|
|
1127
1137
|
model: 'user',
|
|
1128
1138
|
where: [{ field: 'id', value: member.userId }],
|
|
1129
|
-
limit: 1
|
|
1139
|
+
limit: 1,
|
|
1130
1140
|
});
|
|
1131
1141
|
const user = users?.[0];
|
|
1132
1142
|
return {
|
|
@@ -1135,13 +1145,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1135
1145
|
organizationId: member.organizationId,
|
|
1136
1146
|
role: member.role || 'member',
|
|
1137
1147
|
joinedAt: member.joinedAt || member.createdAt,
|
|
1138
|
-
user: user
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1148
|
+
user: user
|
|
1149
|
+
? {
|
|
1150
|
+
id: user.id,
|
|
1151
|
+
name: user.name,
|
|
1152
|
+
email: user.email,
|
|
1153
|
+
image: user.image,
|
|
1154
|
+
emailVerified: user.emailVerified,
|
|
1155
|
+
}
|
|
1156
|
+
: null,
|
|
1145
1157
|
};
|
|
1146
1158
|
}
|
|
1147
1159
|
return null;
|
|
@@ -1151,7 +1163,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1151
1163
|
return null;
|
|
1152
1164
|
}
|
|
1153
1165
|
}));
|
|
1154
|
-
const validMembers = membersWithUsers.filter(member => member && member.user);
|
|
1166
|
+
const validMembers = membersWithUsers.filter((member) => member && member.user);
|
|
1155
1167
|
res.json({ success: true, members: validMembers });
|
|
1156
1168
|
return;
|
|
1157
1169
|
}
|
|
@@ -1196,21 +1208,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1196
1208
|
email,
|
|
1197
1209
|
emailVerified: false,
|
|
1198
1210
|
createdAt: new Date(),
|
|
1199
|
-
updatedAt: new Date()
|
|
1211
|
+
updatedAt: new Date(),
|
|
1200
1212
|
};
|
|
1201
1213
|
const user = await adapter.create({
|
|
1202
1214
|
model: 'user',
|
|
1203
|
-
data: userData
|
|
1215
|
+
data: userData,
|
|
1204
1216
|
});
|
|
1205
1217
|
const memberData = {
|
|
1206
1218
|
organizationId: orgId,
|
|
1207
1219
|
userId: user.id,
|
|
1208
1220
|
role: 'member',
|
|
1209
|
-
createdAt: new Date()
|
|
1221
|
+
createdAt: new Date(),
|
|
1210
1222
|
};
|
|
1211
1223
|
await adapter.create({
|
|
1212
1224
|
model: 'member',
|
|
1213
|
-
data: memberData
|
|
1225
|
+
data: memberData,
|
|
1214
1226
|
});
|
|
1215
1227
|
results.push({
|
|
1216
1228
|
success: true,
|
|
@@ -1218,22 +1230,22 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1218
1230
|
userId: user.id,
|
|
1219
1231
|
user: {
|
|
1220
1232
|
name,
|
|
1221
|
-
email
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1233
|
+
email,
|
|
1234
|
+
},
|
|
1235
|
+
},
|
|
1224
1236
|
});
|
|
1225
1237
|
}
|
|
1226
1238
|
catch (error) {
|
|
1227
1239
|
results.push({
|
|
1228
1240
|
success: false,
|
|
1229
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
1241
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1230
1242
|
});
|
|
1231
1243
|
}
|
|
1232
1244
|
}
|
|
1233
1245
|
res.json({
|
|
1234
1246
|
success: true,
|
|
1235
|
-
message: `Added ${results.filter(r => r.success).length} members`,
|
|
1236
|
-
results
|
|
1247
|
+
message: `Added ${results.filter((r) => r.success).length} members`,
|
|
1248
|
+
results,
|
|
1237
1249
|
});
|
|
1238
1250
|
}
|
|
1239
1251
|
catch (error) {
|
|
@@ -1261,7 +1273,16 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1261
1273
|
return result;
|
|
1262
1274
|
};
|
|
1263
1275
|
const teamNames = [
|
|
1264
|
-
'Engineering',
|
|
1276
|
+
'Engineering',
|
|
1277
|
+
'Design',
|
|
1278
|
+
'Marketing',
|
|
1279
|
+
'Sales',
|
|
1280
|
+
'Support',
|
|
1281
|
+
'Product',
|
|
1282
|
+
'Operations',
|
|
1283
|
+
'Finance',
|
|
1284
|
+
'HR',
|
|
1285
|
+
'Legal',
|
|
1265
1286
|
];
|
|
1266
1287
|
const results = [];
|
|
1267
1288
|
for (let i = 0; i < count; i++) {
|
|
@@ -1272,31 +1293,31 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1272
1293
|
name: teamName,
|
|
1273
1294
|
organizationId: orgId,
|
|
1274
1295
|
createdAt: new Date(),
|
|
1275
|
-
updatedAt: new Date()
|
|
1296
|
+
updatedAt: new Date(),
|
|
1276
1297
|
};
|
|
1277
1298
|
const team = await adapter.create({
|
|
1278
1299
|
model: 'team',
|
|
1279
|
-
data: teamData
|
|
1300
|
+
data: teamData,
|
|
1280
1301
|
});
|
|
1281
1302
|
results.push({
|
|
1282
1303
|
success: true,
|
|
1283
1304
|
team: {
|
|
1284
1305
|
id: team.id,
|
|
1285
|
-
name: teamName
|
|
1286
|
-
}
|
|
1306
|
+
name: teamName,
|
|
1307
|
+
},
|
|
1287
1308
|
});
|
|
1288
1309
|
}
|
|
1289
1310
|
catch (error) {
|
|
1290
1311
|
results.push({
|
|
1291
1312
|
success: false,
|
|
1292
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
1313
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1293
1314
|
});
|
|
1294
1315
|
}
|
|
1295
1316
|
}
|
|
1296
1317
|
res.json({
|
|
1297
1318
|
success: true,
|
|
1298
|
-
message: `Created ${results.filter(r => r.success).length} teams`,
|
|
1299
|
-
results
|
|
1319
|
+
message: `Created ${results.filter((r) => r.success).length} teams`,
|
|
1320
|
+
results,
|
|
1300
1321
|
});
|
|
1301
1322
|
}
|
|
1302
1323
|
catch (error) {
|
|
@@ -1316,7 +1337,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1316
1337
|
}
|
|
1317
1338
|
await adapter.delete({
|
|
1318
1339
|
model: 'member',
|
|
1319
|
-
where: [{ field: 'id', value: id }]
|
|
1340
|
+
where: [{ field: 'id', value: id }],
|
|
1320
1341
|
});
|
|
1321
1342
|
res.json({ success: true });
|
|
1322
1343
|
}
|
|
@@ -1340,8 +1361,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1340
1361
|
where: [{ field: 'id', value: id }],
|
|
1341
1362
|
update: {
|
|
1342
1363
|
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
|
|
1343
|
-
updatedAt: new Date().toISOString()
|
|
1344
|
-
}
|
|
1364
|
+
updatedAt: new Date().toISOString(),
|
|
1365
|
+
},
|
|
1345
1366
|
});
|
|
1346
1367
|
res.json({ success: true });
|
|
1347
1368
|
}
|
|
@@ -1365,8 +1386,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1365
1386
|
where: [{ field: 'id', value: id }],
|
|
1366
1387
|
update: {
|
|
1367
1388
|
status: 'cancelled',
|
|
1368
|
-
updatedAt: new Date().toISOString()
|
|
1369
|
-
}
|
|
1389
|
+
updatedAt: new Date().toISOString(),
|
|
1390
|
+
},
|
|
1370
1391
|
});
|
|
1371
1392
|
res.json({ success: true });
|
|
1372
1393
|
}
|
|
@@ -1393,11 +1414,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1393
1414
|
status: 'pending',
|
|
1394
1415
|
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
|
|
1395
1416
|
createdAt: new Date(),
|
|
1396
|
-
inviterId: inviterId
|
|
1417
|
+
inviterId: inviterId,
|
|
1397
1418
|
};
|
|
1398
1419
|
const invitation = {
|
|
1399
1420
|
id: `inv_${Date.now()}`,
|
|
1400
|
-
...invitationData
|
|
1421
|
+
...invitationData,
|
|
1401
1422
|
};
|
|
1402
1423
|
if (!adapter.create) {
|
|
1403
1424
|
return res.status(500).json({ error: 'Adapter create method not available' });
|
|
@@ -1412,7 +1433,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1412
1433
|
inviterId: invitationData.inviterId,
|
|
1413
1434
|
expiresAt: invitationData.expiresAt,
|
|
1414
1435
|
createdAt: invitationData.createdAt,
|
|
1415
|
-
}
|
|
1436
|
+
},
|
|
1416
1437
|
});
|
|
1417
1438
|
res.json({ success: true, invitation });
|
|
1418
1439
|
}
|
|
@@ -1430,7 +1451,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1430
1451
|
const teams = await adapter.findMany({
|
|
1431
1452
|
model: 'team',
|
|
1432
1453
|
where: [{ field: 'organizationId', value: orgId }],
|
|
1433
|
-
limit: 10000
|
|
1454
|
+
limit: 10000,
|
|
1434
1455
|
});
|
|
1435
1456
|
const transformedTeams = await Promise.all((teams || []).map(async (team) => {
|
|
1436
1457
|
if (!adapter.findMany) {
|
|
@@ -1439,7 +1460,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1439
1460
|
const teamMembers = await adapter.findMany({
|
|
1440
1461
|
model: 'teamMember',
|
|
1441
1462
|
where: [{ field: 'teamId', value: team.id }],
|
|
1442
|
-
limit: 10000
|
|
1463
|
+
limit: 10000,
|
|
1443
1464
|
});
|
|
1444
1465
|
return {
|
|
1445
1466
|
id: team.id,
|
|
@@ -1448,7 +1469,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1448
1469
|
metadata: team.metadata,
|
|
1449
1470
|
createdAt: team.createdAt,
|
|
1450
1471
|
updatedAt: team.updatedAt,
|
|
1451
|
-
memberCount: teamMembers ? teamMembers.length : 0
|
|
1472
|
+
memberCount: teamMembers ? teamMembers.length : 0,
|
|
1452
1473
|
};
|
|
1453
1474
|
}));
|
|
1454
1475
|
res.json({ success: true, teams: transformedTeams });
|
|
@@ -1478,11 +1499,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1478
1499
|
organizationId: orgId,
|
|
1479
1500
|
createdAt: new Date(),
|
|
1480
1501
|
updatedAt: new Date(),
|
|
1481
|
-
memberCount: 0
|
|
1502
|
+
memberCount: 0,
|
|
1482
1503
|
};
|
|
1483
1504
|
const team = {
|
|
1484
1505
|
id: `team_${Date.now()}`,
|
|
1485
|
-
...teamData
|
|
1506
|
+
...teamData,
|
|
1486
1507
|
};
|
|
1487
1508
|
if (!adapter.create) {
|
|
1488
1509
|
return res.status(500).json({ error: 'Adapter create method not available' });
|
|
@@ -1494,7 +1515,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1494
1515
|
organizationId: teamData.organizationId,
|
|
1495
1516
|
createdAt: teamData.createdAt,
|
|
1496
1517
|
updatedAt: teamData.updatedAt,
|
|
1497
|
-
}
|
|
1518
|
+
},
|
|
1498
1519
|
});
|
|
1499
1520
|
res.json({ success: true, team });
|
|
1500
1521
|
}
|
|
@@ -1512,7 +1533,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1512
1533
|
const teamMembers = await adapter.findMany({
|
|
1513
1534
|
model: 'teamMember',
|
|
1514
1535
|
where: [{ field: 'teamId', value: teamId }],
|
|
1515
|
-
limit: 10000
|
|
1536
|
+
limit: 10000,
|
|
1516
1537
|
});
|
|
1517
1538
|
const membersWithUsers = await Promise.all((teamMembers || []).map(async (member) => {
|
|
1518
1539
|
try {
|
|
@@ -1520,7 +1541,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1520
1541
|
const users = await adapter.findMany({
|
|
1521
1542
|
model: 'user',
|
|
1522
1543
|
where: [{ field: 'id', value: member.userId }],
|
|
1523
|
-
limit: 1
|
|
1544
|
+
limit: 1,
|
|
1524
1545
|
});
|
|
1525
1546
|
const user = users?.[0];
|
|
1526
1547
|
return {
|
|
@@ -1529,13 +1550,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1529
1550
|
teamId: member.teamId,
|
|
1530
1551
|
role: member.role || 'member',
|
|
1531
1552
|
joinedAt: member.joinedAt || member.createdAt,
|
|
1532
|
-
user: user
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1553
|
+
user: user
|
|
1554
|
+
? {
|
|
1555
|
+
id: user.id,
|
|
1556
|
+
name: user.name,
|
|
1557
|
+
email: user.email,
|
|
1558
|
+
image: user.image,
|
|
1559
|
+
emailVerified: user.emailVerified,
|
|
1560
|
+
}
|
|
1561
|
+
: null,
|
|
1539
1562
|
};
|
|
1540
1563
|
}
|
|
1541
1564
|
return null;
|
|
@@ -1545,7 +1568,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1545
1568
|
return null;
|
|
1546
1569
|
}
|
|
1547
1570
|
}));
|
|
1548
|
-
const validMembers = membersWithUsers.filter(member => member && member.user);
|
|
1571
|
+
const validMembers = membersWithUsers.filter((member) => member && member.user);
|
|
1549
1572
|
res.json({ success: true, members: validMembers });
|
|
1550
1573
|
return;
|
|
1551
1574
|
}
|
|
@@ -1580,8 +1603,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1580
1603
|
teamId,
|
|
1581
1604
|
userId,
|
|
1582
1605
|
role: 'member',
|
|
1583
|
-
createdAt: new Date()
|
|
1584
|
-
}
|
|
1606
|
+
createdAt: new Date(),
|
|
1607
|
+
},
|
|
1585
1608
|
});
|
|
1586
1609
|
results.push({ success: true, userId });
|
|
1587
1610
|
}
|
|
@@ -1589,14 +1612,14 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1589
1612
|
results.push({
|
|
1590
1613
|
success: false,
|
|
1591
1614
|
userId,
|
|
1592
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
1615
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1593
1616
|
});
|
|
1594
1617
|
}
|
|
1595
1618
|
}
|
|
1596
1619
|
res.json({
|
|
1597
1620
|
success: true,
|
|
1598
|
-
message: `Added ${results.filter(r => r.success).length} members`,
|
|
1599
|
-
results
|
|
1621
|
+
message: `Added ${results.filter((r) => r.success).length} members`,
|
|
1622
|
+
results,
|
|
1600
1623
|
});
|
|
1601
1624
|
}
|
|
1602
1625
|
catch (error) {
|
|
@@ -1613,7 +1636,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1613
1636
|
}
|
|
1614
1637
|
await adapter.delete({
|
|
1615
1638
|
model: 'teamMember',
|
|
1616
|
-
where: [{ field: 'id', value: id }]
|
|
1639
|
+
where: [{ field: 'id', value: id }],
|
|
1617
1640
|
});
|
|
1618
1641
|
res.json({ success: true });
|
|
1619
1642
|
}
|
|
@@ -1642,7 +1665,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1642
1665
|
where: [{ field: 'id', value: id }],
|
|
1643
1666
|
update: {
|
|
1644
1667
|
name: updatedTeam.name,
|
|
1645
|
-
}
|
|
1668
|
+
},
|
|
1646
1669
|
});
|
|
1647
1670
|
res.json({ success: true, team: updatedTeam });
|
|
1648
1671
|
}
|
|
@@ -1674,30 +1697,28 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1674
1697
|
});
|
|
1675
1698
|
router.get('/api/plugins/organization/status', async (req, res) => {
|
|
1676
1699
|
try {
|
|
1677
|
-
const authConfigPath = configPath || await findAuthConfigPath();
|
|
1700
|
+
const authConfigPath = configPath || (await findAuthConfigPath());
|
|
1678
1701
|
if (!authConfigPath) {
|
|
1679
1702
|
return res.json({
|
|
1680
1703
|
enabled: false,
|
|
1681
1704
|
error: 'No auth config found',
|
|
1682
|
-
configPath: null
|
|
1705
|
+
configPath: null,
|
|
1683
1706
|
});
|
|
1684
1707
|
}
|
|
1685
1708
|
try {
|
|
1686
|
-
// Use the same logic as the /api/plugins endpoint
|
|
1687
1709
|
let authModule;
|
|
1688
1710
|
try {
|
|
1689
1711
|
authModule = await safeImportAuthConfig(authConfigPath);
|
|
1690
1712
|
}
|
|
1691
1713
|
catch (importError) {
|
|
1692
|
-
// Fallback: read file content directly
|
|
1693
1714
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
1694
1715
|
authModule = {
|
|
1695
1716
|
auth: {
|
|
1696
1717
|
options: {
|
|
1697
1718
|
_content: content,
|
|
1698
|
-
plugins: []
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1719
|
+
plugins: [],
|
|
1720
|
+
},
|
|
1721
|
+
},
|
|
1701
1722
|
};
|
|
1702
1723
|
}
|
|
1703
1724
|
const auth = authModule.auth || authModule.default;
|
|
@@ -1705,16 +1726,16 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1705
1726
|
return res.json({
|
|
1706
1727
|
enabled: false,
|
|
1707
1728
|
error: 'No auth export found',
|
|
1708
|
-
configPath: authConfigPath
|
|
1729
|
+
configPath: authConfigPath,
|
|
1709
1730
|
});
|
|
1710
1731
|
}
|
|
1711
1732
|
const plugins = auth.options?.plugins || [];
|
|
1712
|
-
const hasOrganizationPlugin = plugins.find((plugin) => plugin.id ===
|
|
1733
|
+
const hasOrganizationPlugin = plugins.find((plugin) => plugin.id === 'organization');
|
|
1713
1734
|
res.json({
|
|
1714
1735
|
enabled: !!hasOrganizationPlugin,
|
|
1715
1736
|
configPath: authConfigPath,
|
|
1716
1737
|
availablePlugins: plugins.map((p) => p.id) || [],
|
|
1717
|
-
organizationPlugin: hasOrganizationPlugin || null
|
|
1738
|
+
organizationPlugin: hasOrganizationPlugin || null,
|
|
1718
1739
|
});
|
|
1719
1740
|
}
|
|
1720
1741
|
catch (error) {
|
|
@@ -1725,13 +1746,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1725
1746
|
const { extractBetterAuthConfig } = await import('./config');
|
|
1726
1747
|
const config = extractBetterAuthConfig(content);
|
|
1727
1748
|
if (config && config.plugins) {
|
|
1728
|
-
const hasOrganizationPlugin = config.plugins.find((plugin) => plugin.id ===
|
|
1749
|
+
const hasOrganizationPlugin = config.plugins.find((plugin) => plugin.id === 'organization');
|
|
1729
1750
|
return res.json({
|
|
1730
1751
|
enabled: !!hasOrganizationPlugin,
|
|
1731
1752
|
configPath: authConfigPath,
|
|
1732
1753
|
availablePlugins: config.plugins.map((p) => p.id) || [],
|
|
1733
1754
|
organizationPlugin: hasOrganizationPlugin || null,
|
|
1734
|
-
fallback: true
|
|
1755
|
+
fallback: true,
|
|
1735
1756
|
});
|
|
1736
1757
|
}
|
|
1737
1758
|
}
|
|
@@ -1741,7 +1762,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1741
1762
|
res.json({
|
|
1742
1763
|
enabled: false,
|
|
1743
1764
|
error: 'Failed to load auth config - import failed and regex extraction unavailable',
|
|
1744
|
-
configPath: authConfigPath
|
|
1765
|
+
configPath: authConfigPath,
|
|
1745
1766
|
});
|
|
1746
1767
|
}
|
|
1747
1768
|
}
|
|
@@ -1789,7 +1810,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1789
1810
|
slug: 'acme-corp',
|
|
1790
1811
|
metadata: { status: 'active' },
|
|
1791
1812
|
createdAt: new Date().toISOString(),
|
|
1792
|
-
updatedAt: new Date().toISOString()
|
|
1813
|
+
updatedAt: new Date().toISOString(),
|
|
1793
1814
|
},
|
|
1794
1815
|
{
|
|
1795
1816
|
id: 'org_2',
|
|
@@ -1797,8 +1818,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1797
1818
|
slug: 'tech-solutions',
|
|
1798
1819
|
metadata: { status: 'active' },
|
|
1799
1820
|
createdAt: new Date().toISOString(),
|
|
1800
|
-
updatedAt: new Date().toISOString()
|
|
1801
|
-
}
|
|
1821
|
+
updatedAt: new Date().toISOString(),
|
|
1822
|
+
},
|
|
1802
1823
|
];
|
|
1803
1824
|
res.json({ organizations: mockOrganizations });
|
|
1804
1825
|
}
|
|
@@ -1815,7 +1836,10 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1815
1836
|
}
|
|
1816
1837
|
const orgData = req.body;
|
|
1817
1838
|
if (!orgData.slug && orgData.name) {
|
|
1818
|
-
orgData.slug = orgData.name
|
|
1839
|
+
orgData.slug = orgData.name
|
|
1840
|
+
.toLowerCase()
|
|
1841
|
+
.replace(/\s+/g, '-')
|
|
1842
|
+
.replace(/[^a-z0-9-]/g, '');
|
|
1819
1843
|
}
|
|
1820
1844
|
const organization = await adapter.createOrganization(orgData);
|
|
1821
1845
|
res.json({ success: true, organization });
|
|
@@ -1834,19 +1858,20 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1834
1858
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1835
1859
|
}
|
|
1836
1860
|
if (orgData.name && !orgData.slug) {
|
|
1837
|
-
orgData.slug = orgData.name
|
|
1861
|
+
orgData.slug = orgData.name
|
|
1862
|
+
.toLowerCase()
|
|
1863
|
+
.replace(/\s+/g, '-')
|
|
1864
|
+
.replace(/[^a-z0-9-]/g, '');
|
|
1838
1865
|
}
|
|
1839
1866
|
const updatedOrganization = {
|
|
1840
1867
|
id,
|
|
1841
1868
|
...orgData,
|
|
1842
|
-
updatedAt: new Date().toISOString()
|
|
1869
|
+
updatedAt: new Date().toISOString(),
|
|
1843
1870
|
};
|
|
1844
1871
|
const updatedOrg = await adapter.update({
|
|
1845
1872
|
model: 'organization',
|
|
1846
|
-
where: [
|
|
1847
|
-
|
|
1848
|
-
],
|
|
1849
|
-
update: updatedOrganization
|
|
1873
|
+
where: [{ field: 'id', value: id }],
|
|
1874
|
+
update: updatedOrganization,
|
|
1850
1875
|
});
|
|
1851
1876
|
res.json({ success: true, organization: updatedOrg });
|
|
1852
1877
|
}
|
|
@@ -1864,9 +1889,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1864
1889
|
}
|
|
1865
1890
|
const deletedOrg = await adapter.delete({
|
|
1866
1891
|
model: 'organization',
|
|
1867
|
-
where: [
|
|
1868
|
-
{ field: 'id', value: id }
|
|
1869
|
-
]
|
|
1892
|
+
where: [{ field: 'id', value: id }],
|
|
1870
1893
|
});
|
|
1871
1894
|
res.json({ success: true, organization: deletedOrg });
|
|
1872
1895
|
}
|
|
@@ -1924,21 +1947,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1924
1947
|
name: user.name,
|
|
1925
1948
|
emailVerified: user.emailVerified,
|
|
1926
1949
|
image: user.image,
|
|
1927
|
-
createdAt: user.createdAt
|
|
1928
|
-
}
|
|
1950
|
+
createdAt: user.createdAt,
|
|
1951
|
+
},
|
|
1929
1952
|
});
|
|
1930
1953
|
}
|
|
1931
1954
|
catch (error) {
|
|
1932
1955
|
results.push({
|
|
1933
1956
|
success: false,
|
|
1934
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
1957
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1935
1958
|
});
|
|
1936
1959
|
}
|
|
1937
1960
|
}
|
|
1938
1961
|
res.json({
|
|
1939
1962
|
success: true,
|
|
1940
|
-
message: `Seeded ${results.filter(r => r.success).length} users`,
|
|
1941
|
-
results
|
|
1963
|
+
message: `Seeded ${results.filter((r) => r.success).length} users`,
|
|
1964
|
+
results,
|
|
1942
1965
|
});
|
|
1943
1966
|
}
|
|
1944
1967
|
catch (error) {
|
|
@@ -1974,21 +1997,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
1974
1997
|
userId: session.userId,
|
|
1975
1998
|
expires: session.expires,
|
|
1976
1999
|
sessionToken: session.sessionToken,
|
|
1977
|
-
createdAt: session.createdAt
|
|
1978
|
-
}
|
|
2000
|
+
createdAt: session.createdAt,
|
|
2001
|
+
},
|
|
1979
2002
|
});
|
|
1980
2003
|
}
|
|
1981
2004
|
catch (error) {
|
|
1982
2005
|
results.push({
|
|
1983
2006
|
success: false,
|
|
1984
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
2007
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
1985
2008
|
});
|
|
1986
2009
|
}
|
|
1987
2010
|
}
|
|
1988
2011
|
res.json({
|
|
1989
2012
|
success: true,
|
|
1990
|
-
message: `Seeded ${results.filter(r => r.success).length} sessions`,
|
|
1991
|
-
results
|
|
2013
|
+
message: `Seeded ${results.filter((r) => r.success).length} sessions`,
|
|
2014
|
+
results,
|
|
1992
2015
|
});
|
|
1993
2016
|
}
|
|
1994
2017
|
catch (error) {
|
|
@@ -2004,8 +2027,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2004
2027
|
if (!adapter) {
|
|
2005
2028
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
2006
2029
|
}
|
|
2007
|
-
// @ts-
|
|
2008
|
-
const user = await adapter.findOne({
|
|
2030
|
+
// @ts-expect-error
|
|
2031
|
+
const user = await adapter.findOne({
|
|
2032
|
+
model: 'user',
|
|
2033
|
+
where: [{ field: 'id', value: userId }],
|
|
2034
|
+
});
|
|
2009
2035
|
if (!user) {
|
|
2010
2036
|
return res.status(404).json({ error: 'User not found' });
|
|
2011
2037
|
}
|
|
@@ -2026,21 +2052,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2026
2052
|
ipAddress: session.ipAddress,
|
|
2027
2053
|
userAgent: session.userAgent,
|
|
2028
2054
|
createdAt: session.createdAt,
|
|
2029
|
-
updatedAt: session.updatedAt
|
|
2030
|
-
}
|
|
2055
|
+
updatedAt: session.updatedAt,
|
|
2056
|
+
},
|
|
2031
2057
|
});
|
|
2032
2058
|
}
|
|
2033
2059
|
catch (error) {
|
|
2034
2060
|
results.push({
|
|
2035
2061
|
success: false,
|
|
2036
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
2062
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
2037
2063
|
});
|
|
2038
2064
|
}
|
|
2039
2065
|
}
|
|
2040
2066
|
res.json({
|
|
2041
2067
|
success: true,
|
|
2042
|
-
message: `Seeded ${results.filter(r => r.success).length} sessions for user`,
|
|
2043
|
-
results
|
|
2068
|
+
message: `Seeded ${results.filter((r) => r.success).length} sessions for user`,
|
|
2069
|
+
results,
|
|
2044
2070
|
});
|
|
2045
2071
|
}
|
|
2046
2072
|
catch (error) {
|
|
@@ -2077,21 +2103,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2077
2103
|
type: account.type,
|
|
2078
2104
|
provider: account.provider,
|
|
2079
2105
|
providerAccountId: account.providerAccountId,
|
|
2080
|
-
createdAt: account.createdAt
|
|
2081
|
-
}
|
|
2106
|
+
createdAt: account.createdAt,
|
|
2107
|
+
},
|
|
2082
2108
|
});
|
|
2083
2109
|
}
|
|
2084
2110
|
catch (error) {
|
|
2085
2111
|
results.push({
|
|
2086
2112
|
success: false,
|
|
2087
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
2113
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
2088
2114
|
});
|
|
2089
2115
|
}
|
|
2090
2116
|
}
|
|
2091
2117
|
res.json({
|
|
2092
2118
|
success: true,
|
|
2093
|
-
message: `Seeded ${results.filter(r => r.success).length} accounts`,
|
|
2094
|
-
results
|
|
2119
|
+
message: `Seeded ${results.filter((r) => r.success).length} accounts`,
|
|
2120
|
+
results,
|
|
2095
2121
|
});
|
|
2096
2122
|
}
|
|
2097
2123
|
catch (error) {
|
|
@@ -2120,21 +2146,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2120
2146
|
identifier: verification.identifier,
|
|
2121
2147
|
token: verification.token,
|
|
2122
2148
|
expires: verification.expires,
|
|
2123
|
-
createdAt: verification.createdAt
|
|
2124
|
-
}
|
|
2149
|
+
createdAt: verification.createdAt,
|
|
2150
|
+
},
|
|
2125
2151
|
});
|
|
2126
2152
|
}
|
|
2127
2153
|
catch (error) {
|
|
2128
2154
|
results.push({
|
|
2129
2155
|
success: false,
|
|
2130
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
2156
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
2131
2157
|
});
|
|
2132
2158
|
}
|
|
2133
2159
|
}
|
|
2134
2160
|
res.json({
|
|
2135
2161
|
success: true,
|
|
2136
|
-
message: `Seeded ${results.filter(r => r.success).length} verifications`,
|
|
2137
|
-
results
|
|
2162
|
+
message: `Seeded ${results.filter((r) => r.success).length} verifications`,
|
|
2163
|
+
results,
|
|
2138
2164
|
});
|
|
2139
2165
|
}
|
|
2140
2166
|
catch (error) {
|
|
@@ -2167,7 +2193,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2167
2193
|
slug: generateSlug(organizationName),
|
|
2168
2194
|
image: `https://api.dicebear.com/7.x/identicon/svg?seed=${randomSuffix}`,
|
|
2169
2195
|
createdAt: new Date(),
|
|
2170
|
-
updatedAt: new Date()
|
|
2196
|
+
updatedAt: new Date(),
|
|
2171
2197
|
};
|
|
2172
2198
|
const organization = await adapter.createOrganization(organizationData);
|
|
2173
2199
|
results.push({
|
|
@@ -2177,21 +2203,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
|
|
|
2177
2203
|
name: organization.name,
|
|
2178
2204
|
slug: organization.slug,
|
|
2179
2205
|
image: organization.image,
|
|
2180
|
-
createdAt: organization.createdAt
|
|
2181
|
-
}
|
|
2206
|
+
createdAt: organization.createdAt,
|
|
2207
|
+
},
|
|
2182
2208
|
});
|
|
2183
2209
|
}
|
|
2184
2210
|
catch (error) {
|
|
2185
2211
|
results.push({
|
|
2186
2212
|
success: false,
|
|
2187
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
2213
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
2188
2214
|
});
|
|
2189
2215
|
}
|
|
2190
2216
|
}
|
|
2191
2217
|
res.json({
|
|
2192
2218
|
success: true,
|
|
2193
|
-
message: `Seeded ${results.filter(r => r.success).length} organizations`,
|
|
2194
|
-
results
|
|
2219
|
+
message: `Seeded ${results.filter((r) => r.success).length} organizations`,
|
|
2220
|
+
results,
|
|
2195
2221
|
});
|
|
2196
2222
|
}
|
|
2197
2223
|
catch (error) {
|