better-auth-studio 1.0.20-beta.3 → 1.0.20-beta.6

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/routes.js CHANGED
@@ -1,11 +1,25 @@
1
1
  import { Router } from 'express';
2
- import { getAuthData } from './data.js';
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 { readFileSync, existsSync } from 'fs';
7
- import { join, dirname } from 'path';
8
- import { pathToFileURL } from 'url';
4
+ import { dirname, join } from 'path';
5
+ import { pathToFileURL, fileURLToPath } 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
+ function getStudioVersion() {
10
+ try {
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ const packageJsonPath = join(__dirname, '../package.json');
13
+ if (existsSync(packageJsonPath)) {
14
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
15
+ return packageJson.version || '1.0.0';
16
+ }
17
+ }
18
+ catch (error) {
19
+ console.warn('Failed to read package.json for version:', error);
20
+ }
21
+ return '1.0.0';
22
+ }
9
23
  function resolveModuleWithExtensions(id, parent) {
10
24
  if (!id.startsWith('./') && !id.startsWith('../')) {
11
25
  return id;
@@ -55,7 +69,7 @@ export async function safeImportAuthConfig(authConfigPath) {
55
69
  join(authConfigDir, importName, 'index.ts'),
56
70
  join(authConfigDir, importName, 'index.js'),
57
71
  join(authConfigDir, importName, 'index.mjs'),
58
- join(authConfigDir, importName, 'index.cjs')
72
+ join(authConfigDir, importName, 'index.cjs'),
59
73
  ];
60
74
  for (const path of possiblePaths) {
61
75
  if (existsSync(path)) {
@@ -69,7 +83,7 @@ export async function safeImportAuthConfig(authConfigPath) {
69
83
  fsCache: true,
70
84
  moduleCache: true,
71
85
  interopDefault: true,
72
- alias: aliases
86
+ alias: aliases,
73
87
  });
74
88
  try {
75
89
  return await jiti.import(authConfigPath);
@@ -79,9 +93,9 @@ export async function safeImportAuthConfig(authConfigPath) {
79
93
  return {
80
94
  auth: {
81
95
  options: {
82
- _content: content
83
- }
84
- }
96
+ _content: content,
97
+ },
98
+ },
85
99
  };
86
100
  }
87
101
  }
@@ -169,7 +183,7 @@ async function findAuthConfigPath() {
169
183
  'src/auth.js',
170
184
  'src/auth.ts',
171
185
  'lib/auth.js',
172
- 'lib/auth.ts'
186
+ 'lib/auth.ts',
173
187
  ];
174
188
  for (const path of possiblePaths) {
175
189
  const fullPath = join(process.cwd(), path);
@@ -179,15 +193,13 @@ async function findAuthConfigPath() {
179
193
  }
180
194
  return null;
181
195
  }
196
+ // @ts-nocheck
182
197
  export function createRoutes(authConfig, configPath, geoDbPath) {
183
198
  const router = Router();
184
- // Set geo database path if provided
185
199
  if (geoDbPath) {
186
200
  setGeoDbPath(geoDbPath);
187
201
  }
188
- // Initialize Geo service
189
202
  initializeGeoService().catch(console.error);
190
- // Store the config path for use in adapter functions
191
203
  const getAuthAdapterWithConfig = () => getAuthAdapter(configPath);
192
204
  router.get('/api/health', (req, res) => {
193
205
  const uptime = process.uptime();
@@ -206,11 +218,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
206
218
  memory: {
207
219
  used: Math.round(process.memoryUsage().heapUsed / 1024 / 1024),
208
220
  total: Math.round(process.memoryUsage().heapTotal / 1024 / 1024),
209
- external: Math.round(process.memoryUsage().external / 1024 / 1024)
221
+ external: Math.round(process.memoryUsage().external / 1024 / 1024),
210
222
  },
211
223
  pid: process.pid,
212
- cwd: process.cwd()
213
- }
224
+ cwd: process.cwd(),
225
+ },
214
226
  });
215
227
  });
216
228
  // IP Geolocation endpoint
@@ -220,26 +232,26 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
220
232
  if (!ipAddress) {
221
233
  return res.status(400).json({
222
234
  success: false,
223
- error: 'IP address is required'
235
+ error: 'IP address is required',
224
236
  });
225
237
  }
226
238
  const location = resolveIPLocation(ipAddress);
227
239
  if (!location) {
228
240
  return res.status(404).json({
229
241
  success: false,
230
- error: 'Location not found for IP address'
242
+ error: 'Location not found for IP address',
231
243
  });
232
244
  }
233
245
  res.json({
234
246
  success: true,
235
- location
247
+ location,
236
248
  });
237
249
  }
238
250
  catch (error) {
239
251
  console.error('Error resolving IP location:', error);
240
252
  res.status(500).json({
241
253
  success: false,
242
- error: 'Failed to resolve IP location'
254
+ error: 'Failed to resolve IP location',
243
255
  });
244
256
  }
245
257
  });
@@ -275,13 +287,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
275
287
  dialect: authConfig.database?.dialect || authConfig.database?.provider || 'unknown',
276
288
  casing: authConfig.database?.casing || 'camel',
277
289
  debugLogs: authConfig.database?.debugLogs || false,
278
- url: authConfig.database?.url
290
+ url: authConfig.database?.url,
279
291
  },
280
292
  emailVerification: {
281
293
  sendOnSignUp: authConfig.emailVerification?.sendOnSignUp || false,
282
294
  sendOnSignIn: authConfig.emailVerification?.sendOnSignIn || false,
283
295
  autoSignInAfterVerification: authConfig.emailVerification?.autoSignInAfterVerification || false,
284
- expiresIn: authConfig.emailVerification?.expiresIn || 3600
296
+ expiresIn: authConfig.emailVerification?.expiresIn || 3600,
285
297
  },
286
298
  emailAndPassword: {
287
299
  enabled: authConfig.emailAndPassword?.enabled ?? false,
@@ -291,26 +303,26 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
291
303
  minPasswordLength: authConfig.emailAndPassword?.minPasswordLength ?? 8,
292
304
  resetPasswordTokenExpiresIn: authConfig.emailAndPassword?.resetPasswordTokenExpiresIn ?? 3600,
293
305
  autoSignIn: authConfig.emailAndPassword?.autoSignIn ?? true, // defaults to true
294
- revokeSessionsOnPasswordReset: authConfig.emailAndPassword?.revokeSessionsOnPasswordReset ?? false
306
+ revokeSessionsOnPasswordReset: authConfig.emailAndPassword?.revokeSessionsOnPasswordReset ?? false,
295
307
  },
296
- socialProviders: authConfig.socialProviders ?
297
- Object.entries(authConfig.socialProviders).map(([provider, config]) => ({
308
+ socialProviders: authConfig.socialProviders
309
+ ? Object.entries(authConfig.socialProviders).map(([provider, config]) => ({
298
310
  type: provider,
299
311
  clientId: config.clientId,
300
312
  clientSecret: config.clientSecret,
301
313
  redirectUri: config.redirectUri,
302
- ...config
303
- })) :
304
- (authConfig.providers || []),
314
+ ...config,
315
+ }))
316
+ : authConfig.providers || [],
305
317
  user: {
306
318
  modelName: authConfig.user?.modelName || 'user',
307
319
  changeEmail: {
308
- enabled: authConfig.user?.changeEmail?.enabled || false
320
+ enabled: authConfig.user?.changeEmail?.enabled || false,
309
321
  },
310
322
  deleteUser: {
311
323
  enabled: authConfig.user?.deleteUser?.enabled || false,
312
- deleteTokenExpiresIn: authConfig.user?.deleteUser?.deleteTokenExpiresIn || 86400
313
- }
324
+ deleteTokenExpiresIn: authConfig.user?.deleteUser?.deleteTokenExpiresIn || 86400,
325
+ },
314
326
  },
315
327
  session: {
316
328
  modelName: authConfig.session?.modelName || 'session',
@@ -321,9 +333,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
321
333
  preserveSessionInDatabase: authConfig.session?.preserveSessionInDatabase || false,
322
334
  cookieCache: {
323
335
  enabled: authConfig.session?.cookieCache?.enabled || false,
324
- maxAge: authConfig.session?.cookieCache?.maxAge || 300
336
+ maxAge: authConfig.session?.cookieCache?.maxAge || 300,
325
337
  },
326
- freshAge: authConfig.session?.freshAge || 86400
338
+ freshAge: authConfig.session?.freshAge || 86400,
327
339
  },
328
340
  account: {
329
341
  modelName: authConfig.account?.modelName || 'account',
@@ -333,13 +345,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
333
345
  trustedProviders: authConfig.account?.accountLinking?.trustedProviders || [],
334
346
  allowDifferentEmails: authConfig.account?.accountLinking?.allowDifferentEmails || false,
335
347
  allowUnlinkingAll: authConfig.account?.accountLinking?.allowUnlinkingAll || false,
336
- updateUserInfoOnLink: authConfig.account?.accountLinking?.updateUserInfoOnLink || false
348
+ updateUserInfoOnLink: authConfig.account?.accountLinking?.updateUserInfoOnLink || false,
337
349
  },
338
- encryptOAuthTokens: authConfig.account?.encryptOAuthTokens || false
350
+ encryptOAuthTokens: authConfig.account?.encryptOAuthTokens || false,
339
351
  },
340
352
  verification: {
341
353
  modelName: authConfig.verification?.modelName || 'verification',
342
- disableCleanup: authConfig.verification?.disableCleanup || false
354
+ disableCleanup: authConfig.verification?.disableCleanup || false,
343
355
  },
344
356
  trustedOrigins: Array.isArray(authConfig.trustedOrigins) ? authConfig.trustedOrigins : [],
345
357
  rateLimit: {
@@ -347,39 +359,39 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
347
359
  window: authConfig.rateLimit?.window || 10,
348
360
  max: authConfig.rateLimit?.max || 100,
349
361
  storage: authConfig.rateLimit?.storage || 'memory',
350
- modelName: authConfig.rateLimit?.modelName || 'rateLimit'
362
+ modelName: authConfig.rateLimit?.modelName || 'rateLimit',
351
363
  },
352
364
  advanced: {
353
365
  ipAddress: {
354
366
  ipAddressHeaders: authConfig.advanced?.ipAddress?.ipAddressHeaders || [],
355
- disableIpTracking: authConfig.advanced?.ipAddress?.disableIpTracking || false
367
+ disableIpTracking: authConfig.advanced?.ipAddress?.disableIpTracking || false,
356
368
  },
357
369
  useSecureCookies: authConfig.advanced?.useSecureCookies || false,
358
370
  disableCSRFCheck: authConfig.advanced?.disableCSRFCheck || false,
359
371
  crossSubDomainCookies: {
360
372
  enabled: authConfig.advanced?.crossSubDomainCookies?.enabled || false,
361
373
  additionalCookies: authConfig.advanced?.crossSubDomainCookies?.additionalCookies || [],
362
- domain: authConfig.advanced?.crossSubDomainCookies?.domain
374
+ domain: authConfig.advanced?.crossSubDomainCookies?.domain,
363
375
  },
364
376
  cookies: authConfig.advanced?.cookies || {},
365
377
  defaultCookieAttributes: authConfig.advanced?.defaultCookieAttributes || {},
366
378
  cookiePrefix: authConfig.advanced?.cookiePrefix,
367
379
  database: {
368
380
  defaultFindManyLimit: authConfig.advanced?.database?.defaultFindManyLimit || 100,
369
- useNumberId: authConfig.advanced?.database?.useNumberId || false
370
- }
381
+ useNumberId: authConfig.advanced?.database?.useNumberId || false,
382
+ },
371
383
  },
372
384
  disabledPaths: authConfig.disabledPaths || [],
373
385
  telemetry: {
374
386
  enabled: authConfig.telemetry?.enabled ?? false,
375
- debug: authConfig.telemetry?.debug || false
387
+ debug: authConfig.telemetry?.debug || false,
376
388
  },
377
389
  studio: {
378
- version: '1.0.0',
390
+ version: getStudioVersion(),
379
391
  nodeVersion: process.version,
380
392
  platform: process.platform,
381
- uptime: process.uptime()
382
- }
393
+ uptime: process.uptime(),
394
+ },
383
395
  };
384
396
  res.json(config);
385
397
  });
@@ -432,7 +444,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
432
444
  res.json({
433
445
  users: userCount,
434
446
  sessions: sessionCount,
435
- organizations: organizationCount
447
+ organizations: organizationCount,
436
448
  });
437
449
  }
438
450
  catch (error) {
@@ -469,7 +481,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
469
481
  const users = await adapter.findMany({
470
482
  model: 'user',
471
483
  where: [{ field: 'id', value: userId }],
472
- limit: 1
484
+ limit: 1,
473
485
  });
474
486
  const user = users && users.length > 0 ? users[0] : null;
475
487
  if (!user) {
@@ -493,7 +505,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
493
505
  const user = await adapter.update({
494
506
  model: 'user',
495
507
  where: [{ field: 'id', value: userId }],
496
- update: { name, email }
508
+ update: { name, email },
497
509
  });
498
510
  res.json({ success: true, user });
499
511
  }
@@ -526,27 +538,29 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
526
538
  }
527
539
  const [memberships, organizations] = await Promise.all([
528
540
  adapter.findMany({ model: 'member', limit: 10000 }),
529
- adapter.findMany({ model: 'organization', limit: 10000 })
541
+ adapter.findMany({ model: 'organization', limit: 10000 }),
530
542
  ]);
531
543
  const userMemberships = memberships.filter((membership) => membership.userId === userId);
532
544
  const formattedMemberships = userMemberships.map((membership) => {
533
545
  const organization = organizations.find((org) => org.id === membership.organizationId);
534
546
  return {
535
547
  id: membership.id,
536
- organization: organization ? {
537
- id: organization.id,
538
- name: organization.name || 'Unknown Organization',
539
- slug: organization.slug || 'unknown',
540
- image: organization.image,
541
- createdAt: organization.createdAt
542
- } : {
543
- id: membership.organizationId,
544
- name: 'Unknown Organization',
545
- slug: 'unknown',
546
- createdAt: membership.createdAt
547
- },
548
+ organization: organization
549
+ ? {
550
+ id: organization.id,
551
+ name: organization.name || 'Unknown Organization',
552
+ slug: organization.slug || 'unknown',
553
+ image: organization.image,
554
+ createdAt: organization.createdAt,
555
+ }
556
+ : {
557
+ id: membership.organizationId,
558
+ name: 'Unknown Organization',
559
+ slug: 'unknown',
560
+ createdAt: membership.createdAt,
561
+ },
548
562
  role: membership.role || 'member',
549
- joinedAt: membership.createdAt
563
+ joinedAt: membership.createdAt,
550
564
  };
551
565
  });
552
566
  res.json({ memberships: formattedMemberships });
@@ -566,27 +580,33 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
566
580
  const [memberships, teams, organizations] = await Promise.all([
567
581
  adapter.findMany({ model: 'teamMember', limit: 10000 }),
568
582
  adapter.findMany({ model: 'team', limit: 10000 }),
569
- adapter.findMany({ model: 'organization', limit: 10000 })
583
+ adapter.findMany({ model: 'organization', limit: 10000 }),
570
584
  ]);
571
585
  const userMemberships = memberships.filter((membership) => membership.userId === userId);
572
586
  const formattedMemberships = userMemberships.map((membership) => {
573
587
  const team = teams.find((t) => t.id === membership.teamId);
574
- const organization = team ? organizations.find((org) => org.id === team.organizationId) : null;
588
+ const organization = team
589
+ ? organizations.find((org) => org.id === team.organizationId)
590
+ : null;
575
591
  return {
576
592
  id: membership.id,
577
- team: team ? {
578
- id: team.id,
579
- name: team.name || 'Unknown Team',
580
- organizationId: team.organizationId,
581
- organizationName: organization ? organization.name || 'Unknown Organization' : 'Unknown Organization'
582
- } : {
583
- id: membership.teamId,
584
- name: 'Unknown Team',
585
- organizationId: 'unknown',
586
- organizationName: 'Unknown Organization'
587
- },
593
+ team: team
594
+ ? {
595
+ id: team.id,
596
+ name: team.name || 'Unknown Team',
597
+ organizationId: team.organizationId,
598
+ organizationName: organization
599
+ ? organization.name || 'Unknown Organization'
600
+ : 'Unknown Organization',
601
+ }
602
+ : {
603
+ id: membership.teamId,
604
+ name: 'Unknown Team',
605
+ organizationId: 'unknown',
606
+ organizationName: 'Unknown Organization',
607
+ },
588
608
  role: membership.role || 'member',
589
- joinedAt: membership.createdAt
609
+ joinedAt: membership.createdAt,
590
610
  };
591
611
  });
592
612
  res.json({ memberships: formattedMemberships });
@@ -636,7 +656,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
636
656
  const user = await adapter.update({
637
657
  model: 'user',
638
658
  id: userId,
639
- data: { banned: true }
659
+ data: { banned: true },
640
660
  });
641
661
  res.json({ success: true, user });
642
662
  }
@@ -654,7 +674,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
654
674
  }
655
675
  const sessions = await adapter.findMany({
656
676
  model: 'session',
657
- limit: 10000
677
+ limit: 10000,
658
678
  });
659
679
  const userSessions = sessions.filter((session) => session.userId === userId);
660
680
  const formattedSessions = userSessions.map((session) => ({
@@ -666,7 +686,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
666
686
  activeOrganizationId: session.activeOrganizationId,
667
687
  activeTeamId: session.activeTeamId,
668
688
  createdAt: session.createdAt,
669
- updatedAt: session.updatedAt
689
+ updatedAt: session.updatedAt,
670
690
  }));
671
691
  res.json({ sessions: formattedSessions });
672
692
  }
@@ -700,7 +720,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
700
720
  const teams = await adapter.findMany({
701
721
  model: 'team',
702
722
  where: [{ field: 'id', value: teamId }],
703
- limit: 1
723
+ limit: 1,
704
724
  });
705
725
  const team = teams && teams.length > 0 ? teams[0] : null;
706
726
  if (!team) {
@@ -712,7 +732,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
712
732
  const orgs = await adapter.findMany({
713
733
  model: 'organization',
714
734
  where: [{ field: 'id', value: team.organizationId }],
715
- limit: 1
735
+ limit: 1,
716
736
  });
717
737
  organization = orgs && orgs.length > 0 ? orgs[0] : null;
718
738
  }
@@ -727,10 +747,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
727
747
  createdAt: team.createdAt,
728
748
  updatedAt: team.updatedAt,
729
749
  memberCount: team.memberCount || 0,
730
- organization: organization ? {
731
- id: organization.id,
732
- name: organization.name
733
- } : null
750
+ organization: organization
751
+ ? {
752
+ id: organization.id,
753
+ name: organization.name,
754
+ }
755
+ : null,
734
756
  };
735
757
  res.json({ success: true, team: transformedTeam });
736
758
  }
@@ -749,7 +771,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
749
771
  const organizations = await adapter.findMany({
750
772
  model: 'organization',
751
773
  where: [{ field: 'id', value: orgId }],
752
- limit: 1
774
+ limit: 1,
753
775
  });
754
776
  const organization = organizations && organizations.length > 0 ? organizations[0] : null;
755
777
  if (!organization) {
@@ -855,12 +877,14 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
855
877
  });
856
878
  router.get('/api/plugins', async (req, res) => {
857
879
  try {
858
- const authConfigPath = configPath ? join(process.cwd(), configPath) : await findAuthConfigPath();
880
+ const authConfigPath = configPath
881
+ ? join(process.cwd(), configPath)
882
+ : await findAuthConfigPath();
859
883
  if (!authConfigPath) {
860
884
  return res.json({
861
885
  plugins: [],
862
886
  error: 'No auth config found',
863
- configPath: null
887
+ configPath: null,
864
888
  });
865
889
  }
866
890
  try {
@@ -875,9 +899,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
875
899
  auth: {
876
900
  options: {
877
901
  _content: content,
878
- plugins: []
879
- }
880
- }
902
+ plugins: [],
903
+ },
904
+ },
881
905
  };
882
906
  }
883
907
  const auth = authModule.auth || authModule.default;
@@ -885,7 +909,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
885
909
  return res.json({
886
910
  plugins: [],
887
911
  error: 'No auth export found',
888
- configPath: authConfigPath
912
+ configPath: authConfigPath,
889
913
  });
890
914
  }
891
915
  const plugins = auth.options?.plugins || [];
@@ -893,12 +917,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
893
917
  id: plugin.id,
894
918
  name: plugin.name || plugin.id,
895
919
  description: plugin.description || `${plugin.id} plugin for Better Auth`,
896
- enabled: true
920
+ enabled: true,
897
921
  }));
898
922
  res.json({
899
923
  plugins: pluginInfo,
900
924
  configPath: authConfigPath,
901
- totalPlugins: pluginInfo.length
925
+ totalPlugins: pluginInfo.length,
902
926
  });
903
927
  }
904
928
  catch (error) {
@@ -914,13 +938,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
914
938
  name: plugin.name || plugin.id || 'unknown',
915
939
  version: plugin.version || 'unknown',
916
940
  description: plugin.description || `${plugin.id || 'unknown'} plugin for Better Auth`,
917
- enabled: true
941
+ enabled: true,
918
942
  }));
919
943
  return res.json({
920
944
  plugins: pluginInfo,
921
945
  configPath: authConfigPath,
922
946
  totalPlugins: pluginInfo.length,
923
- fallback: true
947
+ fallback: true,
924
948
  });
925
949
  }
926
950
  }
@@ -930,7 +954,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
930
954
  res.json({
931
955
  plugins: [],
932
956
  error: 'Failed to load auth config - import failed and regex extraction unavailable',
933
- configPath: authConfigPath
957
+ configPath: authConfigPath,
934
958
  });
935
959
  }
936
960
  }
@@ -941,12 +965,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
941
965
  });
942
966
  router.get('/api/database/info', async (req, res) => {
943
967
  try {
944
- const authConfigPath = configPath || await findAuthConfigPath();
968
+ const authConfigPath = configPath || (await findAuthConfigPath());
945
969
  if (!authConfigPath) {
946
970
  return res.json({
947
971
  database: null,
948
972
  error: 'No auth config found',
949
- configPath: null
973
+ configPath: null,
950
974
  });
951
975
  }
952
976
  try {
@@ -956,13 +980,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
956
980
  return res.json({
957
981
  database: null,
958
982
  error: 'No auth export found',
959
- configPath: authConfigPath
983
+ configPath: authConfigPath,
960
984
  });
961
985
  }
962
986
  const database = auth.options?.database;
963
987
  res.json({
964
988
  database: database,
965
- configPath: authConfigPath
989
+ configPath: authConfigPath,
966
990
  });
967
991
  }
968
992
  catch (error) {
@@ -976,7 +1000,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
976
1000
  return res.json({
977
1001
  database: config.database,
978
1002
  configPath: authConfigPath,
979
- fallback: true
1003
+ fallback: true,
980
1004
  });
981
1005
  }
982
1006
  }
@@ -986,7 +1010,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
986
1010
  res.json({
987
1011
  database: null,
988
1012
  error: 'Failed to load auth config - import failed and regex extraction unavailable',
989
- configPath: authConfigPath
1013
+ configPath: authConfigPath,
990
1014
  });
991
1015
  }
992
1016
  }
@@ -997,12 +1021,12 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
997
1021
  });
998
1022
  router.get('/api/plugins/teams/status', async (req, res) => {
999
1023
  try {
1000
- const authConfigPath = configPath || await findAuthConfigPath();
1024
+ const authConfigPath = configPath || (await findAuthConfigPath());
1001
1025
  if (!authConfigPath) {
1002
1026
  return res.json({
1003
1027
  enabled: false,
1004
1028
  error: 'No auth config found',
1005
- configPath: null
1029
+ configPath: null,
1006
1030
  });
1007
1031
  }
1008
1032
  try {
@@ -1017,9 +1041,9 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1017
1041
  auth: {
1018
1042
  options: {
1019
1043
  _content: content,
1020
- plugins: []
1021
- }
1022
- }
1044
+ plugins: [],
1045
+ },
1046
+ },
1023
1047
  };
1024
1048
  }
1025
1049
  const auth = authModule.auth || authModule.default;
@@ -1027,15 +1051,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1027
1051
  return res.json({
1028
1052
  enabled: false,
1029
1053
  error: 'No auth export found',
1030
- configPath: authConfigPath
1054
+ configPath: authConfigPath,
1031
1055
  });
1032
1056
  }
1033
- const organizationPlugin = auth.options?.plugins?.find((plugin) => plugin.id === "organization");
1057
+ const organizationPlugin = auth.options?.plugins?.find((plugin) => plugin.id === 'organization');
1034
1058
  const teamsEnabled = organizationPlugin?.teams?.enabled === true;
1035
1059
  res.json({
1036
1060
  enabled: teamsEnabled,
1037
1061
  configPath: authConfigPath,
1038
- organizationPlugin: organizationPlugin || null
1062
+ organizationPlugin: organizationPlugin || null,
1039
1063
  });
1040
1064
  }
1041
1065
  catch (error) {
@@ -1046,13 +1070,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1046
1070
  const { extractBetterAuthConfig } = await import('./config');
1047
1071
  const config = extractBetterAuthConfig(content);
1048
1072
  if (config && config.plugins) {
1049
- const organizationPlugin = config.plugins.find((plugin) => plugin.id === "organization");
1073
+ const organizationPlugin = config.plugins.find((plugin) => plugin.id === 'organization');
1050
1074
  const teamsEnabled = organizationPlugin?.teams?.enabled === true;
1051
1075
  return res.json({
1052
1076
  enabled: teamsEnabled,
1053
1077
  configPath: authConfigPath,
1054
1078
  organizationPlugin: organizationPlugin || null,
1055
- fallback: true
1079
+ fallback: true,
1056
1080
  });
1057
1081
  }
1058
1082
  }
@@ -1062,7 +1086,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1062
1086
  res.json({
1063
1087
  enabled: false,
1064
1088
  error: 'Failed to load auth config - import failed and regex extraction unavailable',
1065
- configPath: authConfigPath
1089
+ configPath: authConfigPath,
1066
1090
  });
1067
1091
  }
1068
1092
  }
@@ -1081,7 +1105,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1081
1105
  model: 'invitation',
1082
1106
  where: [
1083
1107
  { field: 'organizationId', value: orgId },
1084
- { field: 'status', value: 'pending' }
1108
+ { field: 'status', value: 'pending' },
1085
1109
  ],
1086
1110
  });
1087
1111
  const transformedInvitations = (invitations || []).map((invitation) => ({
@@ -1093,7 +1117,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1093
1117
  teamId: invitation.teamId,
1094
1118
  inviterId: invitation.inviterId,
1095
1119
  expiresAt: invitation.expiresAt,
1096
- createdAt: invitation.createdAt
1120
+ createdAt: invitation.createdAt,
1097
1121
  }));
1098
1122
  res.json({ success: true, invitations: transformedInvitations });
1099
1123
  return;
@@ -1118,7 +1142,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1118
1142
  const members = await adapter.findMany({
1119
1143
  model: 'member',
1120
1144
  where: [{ field: 'organizationId', value: orgId }],
1121
- limit: 10000
1145
+ limit: 10000,
1122
1146
  });
1123
1147
  const membersWithUsers = await Promise.all((members || []).map(async (member) => {
1124
1148
  try {
@@ -1126,7 +1150,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1126
1150
  const users = await adapter.findMany({
1127
1151
  model: 'user',
1128
1152
  where: [{ field: 'id', value: member.userId }],
1129
- limit: 1
1153
+ limit: 1,
1130
1154
  });
1131
1155
  const user = users?.[0];
1132
1156
  return {
@@ -1135,13 +1159,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1135
1159
  organizationId: member.organizationId,
1136
1160
  role: member.role || 'member',
1137
1161
  joinedAt: member.joinedAt || member.createdAt,
1138
- user: user ? {
1139
- id: user.id,
1140
- name: user.name,
1141
- email: user.email,
1142
- image: user.image,
1143
- emailVerified: user.emailVerified
1144
- } : null
1162
+ user: user
1163
+ ? {
1164
+ id: user.id,
1165
+ name: user.name,
1166
+ email: user.email,
1167
+ image: user.image,
1168
+ emailVerified: user.emailVerified,
1169
+ }
1170
+ : null,
1145
1171
  };
1146
1172
  }
1147
1173
  return null;
@@ -1151,7 +1177,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1151
1177
  return null;
1152
1178
  }
1153
1179
  }));
1154
- const validMembers = membersWithUsers.filter(member => member && member.user);
1180
+ const validMembers = membersWithUsers.filter((member) => member && member.user);
1155
1181
  res.json({ success: true, members: validMembers });
1156
1182
  return;
1157
1183
  }
@@ -1196,21 +1222,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1196
1222
  email,
1197
1223
  emailVerified: false,
1198
1224
  createdAt: new Date(),
1199
- updatedAt: new Date()
1225
+ updatedAt: new Date(),
1200
1226
  };
1201
1227
  const user = await adapter.create({
1202
1228
  model: 'user',
1203
- data: userData
1229
+ data: userData,
1204
1230
  });
1205
1231
  const memberData = {
1206
1232
  organizationId: orgId,
1207
1233
  userId: user.id,
1208
1234
  role: 'member',
1209
- createdAt: new Date()
1235
+ createdAt: new Date(),
1210
1236
  };
1211
1237
  await adapter.create({
1212
1238
  model: 'member',
1213
- data: memberData
1239
+ data: memberData,
1214
1240
  });
1215
1241
  results.push({
1216
1242
  success: true,
@@ -1218,22 +1244,22 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1218
1244
  userId: user.id,
1219
1245
  user: {
1220
1246
  name,
1221
- email
1222
- }
1223
- }
1247
+ email,
1248
+ },
1249
+ },
1224
1250
  });
1225
1251
  }
1226
1252
  catch (error) {
1227
1253
  results.push({
1228
1254
  success: false,
1229
- error: error instanceof Error ? error.message : 'Unknown error'
1255
+ error: error instanceof Error ? error.message : 'Unknown error',
1230
1256
  });
1231
1257
  }
1232
1258
  }
1233
1259
  res.json({
1234
1260
  success: true,
1235
- message: `Added ${results.filter(r => r.success).length} members`,
1236
- results
1261
+ message: `Added ${results.filter((r) => r.success).length} members`,
1262
+ results,
1237
1263
  });
1238
1264
  }
1239
1265
  catch (error) {
@@ -1261,7 +1287,16 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1261
1287
  return result;
1262
1288
  };
1263
1289
  const teamNames = [
1264
- 'Engineering', 'Design', 'Marketing', 'Sales', 'Support', 'Product', 'Operations', 'Finance', 'HR', 'Legal'
1290
+ 'Engineering',
1291
+ 'Design',
1292
+ 'Marketing',
1293
+ 'Sales',
1294
+ 'Support',
1295
+ 'Product',
1296
+ 'Operations',
1297
+ 'Finance',
1298
+ 'HR',
1299
+ 'Legal',
1265
1300
  ];
1266
1301
  const results = [];
1267
1302
  for (let i = 0; i < count; i++) {
@@ -1272,31 +1307,31 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1272
1307
  name: teamName,
1273
1308
  organizationId: orgId,
1274
1309
  createdAt: new Date(),
1275
- updatedAt: new Date()
1310
+ updatedAt: new Date(),
1276
1311
  };
1277
1312
  const team = await adapter.create({
1278
1313
  model: 'team',
1279
- data: teamData
1314
+ data: teamData,
1280
1315
  });
1281
1316
  results.push({
1282
1317
  success: true,
1283
1318
  team: {
1284
1319
  id: team.id,
1285
- name: teamName
1286
- }
1320
+ name: teamName,
1321
+ },
1287
1322
  });
1288
1323
  }
1289
1324
  catch (error) {
1290
1325
  results.push({
1291
1326
  success: false,
1292
- error: error instanceof Error ? error.message : 'Unknown error'
1327
+ error: error instanceof Error ? error.message : 'Unknown error',
1293
1328
  });
1294
1329
  }
1295
1330
  }
1296
1331
  res.json({
1297
1332
  success: true,
1298
- message: `Created ${results.filter(r => r.success).length} teams`,
1299
- results
1333
+ message: `Created ${results.filter((r) => r.success).length} teams`,
1334
+ results,
1300
1335
  });
1301
1336
  }
1302
1337
  catch (error) {
@@ -1316,7 +1351,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1316
1351
  }
1317
1352
  await adapter.delete({
1318
1353
  model: 'member',
1319
- where: [{ field: 'id', value: id }]
1354
+ where: [{ field: 'id', value: id }],
1320
1355
  });
1321
1356
  res.json({ success: true });
1322
1357
  }
@@ -1340,8 +1375,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1340
1375
  where: [{ field: 'id', value: id }],
1341
1376
  update: {
1342
1377
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
1343
- updatedAt: new Date().toISOString()
1344
- }
1378
+ updatedAt: new Date().toISOString(),
1379
+ },
1345
1380
  });
1346
1381
  res.json({ success: true });
1347
1382
  }
@@ -1365,8 +1400,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1365
1400
  where: [{ field: 'id', value: id }],
1366
1401
  update: {
1367
1402
  status: 'cancelled',
1368
- updatedAt: new Date().toISOString()
1369
- }
1403
+ updatedAt: new Date().toISOString(),
1404
+ },
1370
1405
  });
1371
1406
  res.json({ success: true });
1372
1407
  }
@@ -1393,11 +1428,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1393
1428
  status: 'pending',
1394
1429
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
1395
1430
  createdAt: new Date(),
1396
- inviterId: inviterId
1431
+ inviterId: inviterId,
1397
1432
  };
1398
1433
  const invitation = {
1399
1434
  id: `inv_${Date.now()}`,
1400
- ...invitationData
1435
+ ...invitationData,
1401
1436
  };
1402
1437
  if (!adapter.create) {
1403
1438
  return res.status(500).json({ error: 'Adapter create method not available' });
@@ -1412,7 +1447,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1412
1447
  inviterId: invitationData.inviterId,
1413
1448
  expiresAt: invitationData.expiresAt,
1414
1449
  createdAt: invitationData.createdAt,
1415
- }
1450
+ },
1416
1451
  });
1417
1452
  res.json({ success: true, invitation });
1418
1453
  }
@@ -1430,7 +1465,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1430
1465
  const teams = await adapter.findMany({
1431
1466
  model: 'team',
1432
1467
  where: [{ field: 'organizationId', value: orgId }],
1433
- limit: 10000
1468
+ limit: 10000,
1434
1469
  });
1435
1470
  const transformedTeams = await Promise.all((teams || []).map(async (team) => {
1436
1471
  if (!adapter.findMany) {
@@ -1439,7 +1474,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1439
1474
  const teamMembers = await adapter.findMany({
1440
1475
  model: 'teamMember',
1441
1476
  where: [{ field: 'teamId', value: team.id }],
1442
- limit: 10000
1477
+ limit: 10000,
1443
1478
  });
1444
1479
  return {
1445
1480
  id: team.id,
@@ -1448,7 +1483,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1448
1483
  metadata: team.metadata,
1449
1484
  createdAt: team.createdAt,
1450
1485
  updatedAt: team.updatedAt,
1451
- memberCount: teamMembers ? teamMembers.length : 0
1486
+ memberCount: teamMembers ? teamMembers.length : 0,
1452
1487
  };
1453
1488
  }));
1454
1489
  res.json({ success: true, teams: transformedTeams });
@@ -1478,11 +1513,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1478
1513
  organizationId: orgId,
1479
1514
  createdAt: new Date(),
1480
1515
  updatedAt: new Date(),
1481
- memberCount: 0
1516
+ memberCount: 0,
1482
1517
  };
1483
1518
  const team = {
1484
1519
  id: `team_${Date.now()}`,
1485
- ...teamData
1520
+ ...teamData,
1486
1521
  };
1487
1522
  if (!adapter.create) {
1488
1523
  return res.status(500).json({ error: 'Adapter create method not available' });
@@ -1494,7 +1529,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1494
1529
  organizationId: teamData.organizationId,
1495
1530
  createdAt: teamData.createdAt,
1496
1531
  updatedAt: teamData.updatedAt,
1497
- }
1532
+ },
1498
1533
  });
1499
1534
  res.json({ success: true, team });
1500
1535
  }
@@ -1512,7 +1547,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1512
1547
  const teamMembers = await adapter.findMany({
1513
1548
  model: 'teamMember',
1514
1549
  where: [{ field: 'teamId', value: teamId }],
1515
- limit: 10000
1550
+ limit: 10000,
1516
1551
  });
1517
1552
  const membersWithUsers = await Promise.all((teamMembers || []).map(async (member) => {
1518
1553
  try {
@@ -1520,7 +1555,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1520
1555
  const users = await adapter.findMany({
1521
1556
  model: 'user',
1522
1557
  where: [{ field: 'id', value: member.userId }],
1523
- limit: 1
1558
+ limit: 1,
1524
1559
  });
1525
1560
  const user = users?.[0];
1526
1561
  return {
@@ -1529,13 +1564,15 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1529
1564
  teamId: member.teamId,
1530
1565
  role: member.role || 'member',
1531
1566
  joinedAt: member.joinedAt || member.createdAt,
1532
- user: user ? {
1533
- id: user.id,
1534
- name: user.name,
1535
- email: user.email,
1536
- image: user.image,
1537
- emailVerified: user.emailVerified
1538
- } : null
1567
+ user: user
1568
+ ? {
1569
+ id: user.id,
1570
+ name: user.name,
1571
+ email: user.email,
1572
+ image: user.image,
1573
+ emailVerified: user.emailVerified,
1574
+ }
1575
+ : null,
1539
1576
  };
1540
1577
  }
1541
1578
  return null;
@@ -1545,7 +1582,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1545
1582
  return null;
1546
1583
  }
1547
1584
  }));
1548
- const validMembers = membersWithUsers.filter(member => member && member.user);
1585
+ const validMembers = membersWithUsers.filter((member) => member && member.user);
1549
1586
  res.json({ success: true, members: validMembers });
1550
1587
  return;
1551
1588
  }
@@ -1580,8 +1617,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1580
1617
  teamId,
1581
1618
  userId,
1582
1619
  role: 'member',
1583
- createdAt: new Date()
1584
- }
1620
+ createdAt: new Date(),
1621
+ },
1585
1622
  });
1586
1623
  results.push({ success: true, userId });
1587
1624
  }
@@ -1589,14 +1626,14 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1589
1626
  results.push({
1590
1627
  success: false,
1591
1628
  userId,
1592
- error: error instanceof Error ? error.message : 'Unknown error'
1629
+ error: error instanceof Error ? error.message : 'Unknown error',
1593
1630
  });
1594
1631
  }
1595
1632
  }
1596
1633
  res.json({
1597
1634
  success: true,
1598
- message: `Added ${results.filter(r => r.success).length} members`,
1599
- results
1635
+ message: `Added ${results.filter((r) => r.success).length} members`,
1636
+ results,
1600
1637
  });
1601
1638
  }
1602
1639
  catch (error) {
@@ -1613,7 +1650,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1613
1650
  }
1614
1651
  await adapter.delete({
1615
1652
  model: 'teamMember',
1616
- where: [{ field: 'id', value: id }]
1653
+ where: [{ field: 'id', value: id }],
1617
1654
  });
1618
1655
  res.json({ success: true });
1619
1656
  }
@@ -1642,7 +1679,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1642
1679
  where: [{ field: 'id', value: id }],
1643
1680
  update: {
1644
1681
  name: updatedTeam.name,
1645
- }
1682
+ },
1646
1683
  });
1647
1684
  res.json({ success: true, team: updatedTeam });
1648
1685
  }
@@ -1674,30 +1711,28 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1674
1711
  });
1675
1712
  router.get('/api/plugins/organization/status', async (req, res) => {
1676
1713
  try {
1677
- const authConfigPath = configPath || await findAuthConfigPath();
1714
+ const authConfigPath = configPath || (await findAuthConfigPath());
1678
1715
  if (!authConfigPath) {
1679
1716
  return res.json({
1680
1717
  enabled: false,
1681
1718
  error: 'No auth config found',
1682
- configPath: null
1719
+ configPath: null,
1683
1720
  });
1684
1721
  }
1685
1722
  try {
1686
- // Use the same logic as the /api/plugins endpoint
1687
1723
  let authModule;
1688
1724
  try {
1689
1725
  authModule = await safeImportAuthConfig(authConfigPath);
1690
1726
  }
1691
1727
  catch (importError) {
1692
- // Fallback: read file content directly
1693
1728
  const content = readFileSync(authConfigPath, 'utf-8');
1694
1729
  authModule = {
1695
1730
  auth: {
1696
1731
  options: {
1697
1732
  _content: content,
1698
- plugins: []
1699
- }
1700
- }
1733
+ plugins: [],
1734
+ },
1735
+ },
1701
1736
  };
1702
1737
  }
1703
1738
  const auth = authModule.auth || authModule.default;
@@ -1705,16 +1740,16 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1705
1740
  return res.json({
1706
1741
  enabled: false,
1707
1742
  error: 'No auth export found',
1708
- configPath: authConfigPath
1743
+ configPath: authConfigPath,
1709
1744
  });
1710
1745
  }
1711
1746
  const plugins = auth.options?.plugins || [];
1712
- const hasOrganizationPlugin = plugins.find((plugin) => plugin.id === "organization");
1747
+ const hasOrganizationPlugin = plugins.find((plugin) => plugin.id === 'organization');
1713
1748
  res.json({
1714
1749
  enabled: !!hasOrganizationPlugin,
1715
1750
  configPath: authConfigPath,
1716
1751
  availablePlugins: plugins.map((p) => p.id) || [],
1717
- organizationPlugin: hasOrganizationPlugin || null
1752
+ organizationPlugin: hasOrganizationPlugin || null,
1718
1753
  });
1719
1754
  }
1720
1755
  catch (error) {
@@ -1725,13 +1760,13 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1725
1760
  const { extractBetterAuthConfig } = await import('./config');
1726
1761
  const config = extractBetterAuthConfig(content);
1727
1762
  if (config && config.plugins) {
1728
- const hasOrganizationPlugin = config.plugins.find((plugin) => plugin.id === "organization");
1763
+ const hasOrganizationPlugin = config.plugins.find((plugin) => plugin.id === 'organization');
1729
1764
  return res.json({
1730
1765
  enabled: !!hasOrganizationPlugin,
1731
1766
  configPath: authConfigPath,
1732
1767
  availablePlugins: config.plugins.map((p) => p.id) || [],
1733
1768
  organizationPlugin: hasOrganizationPlugin || null,
1734
- fallback: true
1769
+ fallback: true,
1735
1770
  });
1736
1771
  }
1737
1772
  }
@@ -1741,7 +1776,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1741
1776
  res.json({
1742
1777
  enabled: false,
1743
1778
  error: 'Failed to load auth config - import failed and regex extraction unavailable',
1744
- configPath: authConfigPath
1779
+ configPath: authConfigPath,
1745
1780
  });
1746
1781
  }
1747
1782
  }
@@ -1789,7 +1824,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1789
1824
  slug: 'acme-corp',
1790
1825
  metadata: { status: 'active' },
1791
1826
  createdAt: new Date().toISOString(),
1792
- updatedAt: new Date().toISOString()
1827
+ updatedAt: new Date().toISOString(),
1793
1828
  },
1794
1829
  {
1795
1830
  id: 'org_2',
@@ -1797,8 +1832,8 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1797
1832
  slug: 'tech-solutions',
1798
1833
  metadata: { status: 'active' },
1799
1834
  createdAt: new Date().toISOString(),
1800
- updatedAt: new Date().toISOString()
1801
- }
1835
+ updatedAt: new Date().toISOString(),
1836
+ },
1802
1837
  ];
1803
1838
  res.json({ organizations: mockOrganizations });
1804
1839
  }
@@ -1815,7 +1850,10 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1815
1850
  }
1816
1851
  const orgData = req.body;
1817
1852
  if (!orgData.slug && orgData.name) {
1818
- orgData.slug = orgData.name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
1853
+ orgData.slug = orgData.name
1854
+ .toLowerCase()
1855
+ .replace(/\s+/g, '-')
1856
+ .replace(/[^a-z0-9-]/g, '');
1819
1857
  }
1820
1858
  const organization = await adapter.createOrganization(orgData);
1821
1859
  res.json({ success: true, organization });
@@ -1834,19 +1872,20 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1834
1872
  return res.status(500).json({ error: 'Auth adapter not available' });
1835
1873
  }
1836
1874
  if (orgData.name && !orgData.slug) {
1837
- orgData.slug = orgData.name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
1875
+ orgData.slug = orgData.name
1876
+ .toLowerCase()
1877
+ .replace(/\s+/g, '-')
1878
+ .replace(/[^a-z0-9-]/g, '');
1838
1879
  }
1839
1880
  const updatedOrganization = {
1840
1881
  id,
1841
1882
  ...orgData,
1842
- updatedAt: new Date().toISOString()
1883
+ updatedAt: new Date().toISOString(),
1843
1884
  };
1844
1885
  const updatedOrg = await adapter.update({
1845
1886
  model: 'organization',
1846
- where: [
1847
- { field: 'id', value: id }
1848
- ],
1849
- update: updatedOrganization
1887
+ where: [{ field: 'id', value: id }],
1888
+ update: updatedOrganization,
1850
1889
  });
1851
1890
  res.json({ success: true, organization: updatedOrg });
1852
1891
  }
@@ -1864,9 +1903,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1864
1903
  }
1865
1904
  const deletedOrg = await adapter.delete({
1866
1905
  model: 'organization',
1867
- where: [
1868
- { field: 'id', value: id }
1869
- ]
1906
+ where: [{ field: 'id', value: id }],
1870
1907
  });
1871
1908
  res.json({ success: true, organization: deletedOrg });
1872
1909
  }
@@ -1924,21 +1961,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1924
1961
  name: user.name,
1925
1962
  emailVerified: user.emailVerified,
1926
1963
  image: user.image,
1927
- createdAt: user.createdAt
1928
- }
1964
+ createdAt: user.createdAt,
1965
+ },
1929
1966
  });
1930
1967
  }
1931
1968
  catch (error) {
1932
1969
  results.push({
1933
1970
  success: false,
1934
- error: error instanceof Error ? error.message : 'Unknown error'
1971
+ error: error instanceof Error ? error.message : 'Unknown error',
1935
1972
  });
1936
1973
  }
1937
1974
  }
1938
1975
  res.json({
1939
1976
  success: true,
1940
- message: `Seeded ${results.filter(r => r.success).length} users`,
1941
- results
1977
+ message: `Seeded ${results.filter((r) => r.success).length} users`,
1978
+ results,
1942
1979
  });
1943
1980
  }
1944
1981
  catch (error) {
@@ -1974,21 +2011,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
1974
2011
  userId: session.userId,
1975
2012
  expires: session.expires,
1976
2013
  sessionToken: session.sessionToken,
1977
- createdAt: session.createdAt
1978
- }
2014
+ createdAt: session.createdAt,
2015
+ },
1979
2016
  });
1980
2017
  }
1981
2018
  catch (error) {
1982
2019
  results.push({
1983
2020
  success: false,
1984
- error: error instanceof Error ? error.message : 'Unknown error'
2021
+ error: error instanceof Error ? error.message : 'Unknown error',
1985
2022
  });
1986
2023
  }
1987
2024
  }
1988
2025
  res.json({
1989
2026
  success: true,
1990
- message: `Seeded ${results.filter(r => r.success).length} sessions`,
1991
- results
2027
+ message: `Seeded ${results.filter((r) => r.success).length} sessions`,
2028
+ results,
1992
2029
  });
1993
2030
  }
1994
2031
  catch (error) {
@@ -2004,8 +2041,11 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2004
2041
  if (!adapter) {
2005
2042
  return res.status(500).json({ error: 'Auth adapter not available' });
2006
2043
  }
2007
- // @ts-ignore
2008
- const user = await adapter.findOne({ model: 'user', where: [{ field: 'id', value: userId }] });
2044
+ // @ts-expect-error
2045
+ const user = await adapter.findOne({
2046
+ model: 'user',
2047
+ where: [{ field: 'id', value: userId }],
2048
+ });
2009
2049
  if (!user) {
2010
2050
  return res.status(404).json({ error: 'User not found' });
2011
2051
  }
@@ -2026,21 +2066,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2026
2066
  ipAddress: session.ipAddress,
2027
2067
  userAgent: session.userAgent,
2028
2068
  createdAt: session.createdAt,
2029
- updatedAt: session.updatedAt
2030
- }
2069
+ updatedAt: session.updatedAt,
2070
+ },
2031
2071
  });
2032
2072
  }
2033
2073
  catch (error) {
2034
2074
  results.push({
2035
2075
  success: false,
2036
- error: error instanceof Error ? error.message : 'Unknown error'
2076
+ error: error instanceof Error ? error.message : 'Unknown error',
2037
2077
  });
2038
2078
  }
2039
2079
  }
2040
2080
  res.json({
2041
2081
  success: true,
2042
- message: `Seeded ${results.filter(r => r.success).length} sessions for user`,
2043
- results
2082
+ message: `Seeded ${results.filter((r) => r.success).length} sessions for user`,
2083
+ results,
2044
2084
  });
2045
2085
  }
2046
2086
  catch (error) {
@@ -2077,21 +2117,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2077
2117
  type: account.type,
2078
2118
  provider: account.provider,
2079
2119
  providerAccountId: account.providerAccountId,
2080
- createdAt: account.createdAt
2081
- }
2120
+ createdAt: account.createdAt,
2121
+ },
2082
2122
  });
2083
2123
  }
2084
2124
  catch (error) {
2085
2125
  results.push({
2086
2126
  success: false,
2087
- error: error instanceof Error ? error.message : 'Unknown error'
2127
+ error: error instanceof Error ? error.message : 'Unknown error',
2088
2128
  });
2089
2129
  }
2090
2130
  }
2091
2131
  res.json({
2092
2132
  success: true,
2093
- message: `Seeded ${results.filter(r => r.success).length} accounts`,
2094
- results
2133
+ message: `Seeded ${results.filter((r) => r.success).length} accounts`,
2134
+ results,
2095
2135
  });
2096
2136
  }
2097
2137
  catch (error) {
@@ -2120,21 +2160,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2120
2160
  identifier: verification.identifier,
2121
2161
  token: verification.token,
2122
2162
  expires: verification.expires,
2123
- createdAt: verification.createdAt
2124
- }
2163
+ createdAt: verification.createdAt,
2164
+ },
2125
2165
  });
2126
2166
  }
2127
2167
  catch (error) {
2128
2168
  results.push({
2129
2169
  success: false,
2130
- error: error instanceof Error ? error.message : 'Unknown error'
2170
+ error: error instanceof Error ? error.message : 'Unknown error',
2131
2171
  });
2132
2172
  }
2133
2173
  }
2134
2174
  res.json({
2135
2175
  success: true,
2136
- message: `Seeded ${results.filter(r => r.success).length} verifications`,
2137
- results
2176
+ message: `Seeded ${results.filter((r) => r.success).length} verifications`,
2177
+ results,
2138
2178
  });
2139
2179
  }
2140
2180
  catch (error) {
@@ -2167,7 +2207,7 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2167
2207
  slug: generateSlug(organizationName),
2168
2208
  image: `https://api.dicebear.com/7.x/identicon/svg?seed=${randomSuffix}`,
2169
2209
  createdAt: new Date(),
2170
- updatedAt: new Date()
2210
+ updatedAt: new Date(),
2171
2211
  };
2172
2212
  const organization = await adapter.createOrganization(organizationData);
2173
2213
  results.push({
@@ -2177,21 +2217,21 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
2177
2217
  name: organization.name,
2178
2218
  slug: organization.slug,
2179
2219
  image: organization.image,
2180
- createdAt: organization.createdAt
2181
- }
2220
+ createdAt: organization.createdAt,
2221
+ },
2182
2222
  });
2183
2223
  }
2184
2224
  catch (error) {
2185
2225
  results.push({
2186
2226
  success: false,
2187
- error: error instanceof Error ? error.message : 'Unknown error'
2227
+ error: error instanceof Error ? error.message : 'Unknown error',
2188
2228
  });
2189
2229
  }
2190
2230
  }
2191
2231
  res.json({
2192
2232
  success: true,
2193
- message: `Seeded ${results.filter(r => r.success).length} organizations`,
2194
- results
2233
+ message: `Seeded ${results.filter((r) => r.success).length} organizations`,
2234
+ results,
2195
2235
  });
2196
2236
  }
2197
2237
  catch (error) {