better-auth-studio 1.0.9-beta.5 → 1.0.9-beta.7
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 +91 -51
- package/dist/auth-adapter.js.map +1 -1
- package/dist/cli.js +16 -21
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +112 -47
- 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 +3 -6
- package/dist/data.js.map +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +175 -101
- 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 +33 -35
- package/dist/studio.js.map +1 -1
- package/package.json +2 -1
- package/public/assets/{main-CQ5PeEpQ.js → main-D5Exq71w.js} +12 -12
- package/public/index.html +1 -1
package/dist/routes.js
CHANGED
|
@@ -1,56 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { getAuthData } from './data.js';
|
|
3
|
+
import { getAuthAdapter, createMockUser, createMockSession, createMockAccount, createMockVerification } from './auth-adapter.js';
|
|
4
|
+
import { createJiti } from 'jiti';
|
|
5
|
+
import { readFileSync, existsSync } from 'fs';
|
|
6
|
+
import { join, dirname } from 'path';
|
|
7
|
+
import { pathToFileURL } from 'url';
|
|
8
|
+
// Custom module resolver that tries both .js and .ts extensions
|
|
9
|
+
function resolveModuleWithExtensions(id, parent) {
|
|
10
|
+
// If it's not a relative import, return as is
|
|
11
|
+
if (!id.startsWith('./') && !id.startsWith('../')) {
|
|
12
|
+
return id;
|
|
7
13
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const express_1 = require("express");
|
|
39
|
-
const data_1 = require("./data");
|
|
40
|
-
const auth_adapter_1 = require("./auth-adapter");
|
|
14
|
+
const parentDir = dirname(parent);
|
|
15
|
+
const basePath = join(parentDir, id);
|
|
16
|
+
console.log(`Resolving ${id} from ${parent}`);
|
|
17
|
+
console.log(`Base path: ${basePath}`);
|
|
18
|
+
// Try different extensions in order of preference
|
|
19
|
+
const extensions = ['.ts', '.js', '.mjs', '.cjs'];
|
|
20
|
+
for (const ext of extensions) {
|
|
21
|
+
const fullPath = basePath + ext;
|
|
22
|
+
console.log(`Trying: ${fullPath}`);
|
|
23
|
+
if (existsSync(fullPath)) {
|
|
24
|
+
console.log(`✅ Found: ${fullPath}`);
|
|
25
|
+
return pathToFileURL(fullPath).href;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Special case: if it's a directory, try index files
|
|
29
|
+
if (existsSync(basePath)) {
|
|
30
|
+
console.log(`Found directory: ${basePath}, trying index files`);
|
|
31
|
+
for (const ext of extensions) {
|
|
32
|
+
const indexPath = join(basePath, 'index' + ext);
|
|
33
|
+
console.log(`Trying index: ${indexPath}`);
|
|
34
|
+
if (existsSync(indexPath)) {
|
|
35
|
+
console.log(`✅ Found index: ${indexPath}`);
|
|
36
|
+
return pathToFileURL(indexPath).href;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// If no file found, return the original id
|
|
41
|
+
console.log(`❌ Could not resolve ${id} with any extension, using original`);
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
41
44
|
// Helper function to properly resolve imports from the project's context
|
|
42
|
-
async function safeImportAuthConfig(authConfigPath) {
|
|
45
|
+
export async function safeImportAuthConfig(authConfigPath) {
|
|
43
46
|
try {
|
|
44
|
-
//
|
|
45
|
-
|
|
47
|
+
// For TypeScript files, use Jiti for safe resolution
|
|
48
|
+
if (authConfigPath.endsWith('.ts')) {
|
|
49
|
+
console.log(`Using Jiti to safely import TypeScript config from ${authConfigPath}...`);
|
|
50
|
+
// Create aliases for all relative imports dynamically
|
|
51
|
+
const aliases = {};
|
|
52
|
+
// Get the directory of the auth config file
|
|
53
|
+
const authConfigDir = dirname(authConfigPath);
|
|
54
|
+
// Read the file content to find all relative imports
|
|
55
|
+
const content = readFileSync(authConfigPath, 'utf-8');
|
|
56
|
+
// Find all relative imports (./something or ../something)
|
|
57
|
+
const relativeImportRegex = /import\s+.*?\s+from\s+['"](\.\/[^'"]+)['"]/g;
|
|
58
|
+
const dynamicImportRegex = /import\s*\(\s*['"](\.\/[^'"]+)['"]\s*\)/g;
|
|
59
|
+
const foundImports = new Set();
|
|
60
|
+
// Extract relative imports from static imports
|
|
61
|
+
let match;
|
|
62
|
+
while ((match = relativeImportRegex.exec(content)) !== null) {
|
|
63
|
+
foundImports.add(match[1]);
|
|
64
|
+
}
|
|
65
|
+
// Extract relative imports from dynamic imports
|
|
66
|
+
while ((match = dynamicImportRegex.exec(content)) !== null) {
|
|
67
|
+
foundImports.add(match[1]);
|
|
68
|
+
}
|
|
69
|
+
console.log(`Found relative imports: ${Array.from(foundImports).join(', ')}`);
|
|
70
|
+
// Create aliases for each found import
|
|
71
|
+
for (const importPath of foundImports) {
|
|
72
|
+
const importName = importPath.replace('./', '');
|
|
73
|
+
const possiblePaths = [
|
|
74
|
+
join(authConfigDir, importName + '.ts'),
|
|
75
|
+
join(authConfigDir, importName + '.js'),
|
|
76
|
+
join(authConfigDir, importName + '.mjs'),
|
|
77
|
+
join(authConfigDir, importName + '.cjs'),
|
|
78
|
+
join(authConfigDir, importName, 'index.ts'),
|
|
79
|
+
join(authConfigDir, importName, 'index.js'),
|
|
80
|
+
join(authConfigDir, importName, 'index.mjs'),
|
|
81
|
+
join(authConfigDir, importName, 'index.cjs')
|
|
82
|
+
];
|
|
83
|
+
for (const path of possiblePaths) {
|
|
84
|
+
if (existsSync(path)) {
|
|
85
|
+
aliases[importPath] = pathToFileURL(path).href;
|
|
86
|
+
console.log(`Created alias: ${importPath} -> ${path}`);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const jiti = createJiti(import.meta.url, {
|
|
92
|
+
debug: true, // Enable debug to see what's happening
|
|
93
|
+
fsCache: true,
|
|
94
|
+
moduleCache: true,
|
|
95
|
+
interopDefault: true,
|
|
96
|
+
alias: aliases
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
return await jiti.import(authConfigPath);
|
|
100
|
+
}
|
|
101
|
+
catch (importError) {
|
|
102
|
+
console.log(`Jiti import failed: ${importError.message}`);
|
|
103
|
+
console.log('Falling back to regex extraction...');
|
|
104
|
+
// If Jiti import fails, fall back to regex extraction
|
|
105
|
+
const content = readFileSync(authConfigPath, 'utf-8');
|
|
106
|
+
console.log('Using regex extraction as fallback');
|
|
107
|
+
// Return a mock module that can be processed by regex extraction
|
|
108
|
+
return {
|
|
109
|
+
auth: {
|
|
110
|
+
options: {
|
|
111
|
+
// This will be processed by regex extraction
|
|
112
|
+
_content: content
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// For JavaScript files, try normal import first
|
|
119
|
+
return await import(authConfigPath);
|
|
46
120
|
}
|
|
47
121
|
catch (importError) {
|
|
48
|
-
console.log('
|
|
122
|
+
console.log('Import failed, trying to resolve imports from project context...');
|
|
49
123
|
try {
|
|
50
124
|
// Get the project directory from the auth config path
|
|
51
|
-
const { dirname, join } = await
|
|
52
|
-
const { existsSync, readFileSync, writeFileSync, mkdtempSync, unlinkSync, rmdirSync } = await
|
|
53
|
-
const { tmpdir } = await
|
|
125
|
+
const { dirname, join } = await import('path');
|
|
126
|
+
const { existsSync, readFileSync, writeFileSync, mkdtempSync, unlinkSync, rmdirSync } = await import('fs');
|
|
127
|
+
const { tmpdir } = await import('os');
|
|
54
128
|
const projectDir = dirname(authConfigPath);
|
|
55
129
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
56
130
|
// Create a safe version of the auth config by ignoring problematic imports
|
|
@@ -112,7 +186,7 @@ const magicLink = () => ({ id: 'magic-link', name: 'Magic Link' });`);
|
|
|
112
186
|
process.env.NODE_PATH = nodeModulesPath;
|
|
113
187
|
process.chdir(projectDir);
|
|
114
188
|
// Try to import the resolved auth config
|
|
115
|
-
const authModule = await
|
|
189
|
+
const authModule = await import(tempFile);
|
|
116
190
|
// Clean up temp file
|
|
117
191
|
unlinkSync(tempFile);
|
|
118
192
|
rmdirSync(tempDir);
|
|
@@ -141,8 +215,8 @@ const magicLink = () => ({ id: 'magic-link', name: 'Magic Link' });`);
|
|
|
141
215
|
}
|
|
142
216
|
}
|
|
143
217
|
async function findAuthConfigPath() {
|
|
144
|
-
const { join, dirname } = await
|
|
145
|
-
const { existsSync } = await
|
|
218
|
+
const { join, dirname } = await import('path');
|
|
219
|
+
const { existsSync } = await import('fs');
|
|
146
220
|
const possiblePaths = [
|
|
147
221
|
'auth.js', // Prioritize the working CommonJS file
|
|
148
222
|
'auth.ts',
|
|
@@ -159,8 +233,8 @@ async function findAuthConfigPath() {
|
|
|
159
233
|
}
|
|
160
234
|
return null;
|
|
161
235
|
}
|
|
162
|
-
function createRoutes(authConfig) {
|
|
163
|
-
const router =
|
|
236
|
+
export function createRoutes(authConfig) {
|
|
237
|
+
const router = Router();
|
|
164
238
|
router.get('/api/health', (req, res) => {
|
|
165
239
|
const uptime = process.uptime();
|
|
166
240
|
const hours = Math.floor(uptime / 3600);
|
|
@@ -308,7 +382,7 @@ function createRoutes(authConfig) {
|
|
|
308
382
|
});
|
|
309
383
|
router.get('/api/stats', async (req, res) => {
|
|
310
384
|
try {
|
|
311
|
-
const stats = await
|
|
385
|
+
const stats = await getAuthData(authConfig, 'stats');
|
|
312
386
|
res.json(stats);
|
|
313
387
|
}
|
|
314
388
|
catch (error) {
|
|
@@ -318,7 +392,7 @@ function createRoutes(authConfig) {
|
|
|
318
392
|
});
|
|
319
393
|
router.get('/api/counts', async (req, res) => {
|
|
320
394
|
try {
|
|
321
|
-
const adapter = await
|
|
395
|
+
const adapter = await getAuthAdapter();
|
|
322
396
|
let userCount = 0;
|
|
323
397
|
let sessionCount = 0;
|
|
324
398
|
let organizationCount = 0;
|
|
@@ -366,7 +440,7 @@ function createRoutes(authConfig) {
|
|
|
366
440
|
// Endpoint to fetch all users for selection (e.g., for inviter selection)
|
|
367
441
|
router.get('/api/users/all', async (req, res) => {
|
|
368
442
|
try {
|
|
369
|
-
const adapter = await
|
|
443
|
+
const adapter = await getAuthAdapter();
|
|
370
444
|
if (!adapter) {
|
|
371
445
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
372
446
|
}
|
|
@@ -389,7 +463,7 @@ function createRoutes(authConfig) {
|
|
|
389
463
|
const limit = parseInt(req.query.limit) || 20;
|
|
390
464
|
const search = req.query.search;
|
|
391
465
|
try {
|
|
392
|
-
const adapter = await
|
|
466
|
+
const adapter = await getAuthAdapter();
|
|
393
467
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
394
468
|
const allUsers = await adapter.findMany({ model: 'user', limit: limit });
|
|
395
469
|
console.log('Found users via findMany:', allUsers?.length || 0);
|
|
@@ -417,7 +491,7 @@ function createRoutes(authConfig) {
|
|
|
417
491
|
catch (adapterError) {
|
|
418
492
|
console.error('Error fetching users from adapter:', adapterError);
|
|
419
493
|
}
|
|
420
|
-
const result = await
|
|
494
|
+
const result = await getAuthData(authConfig, 'users', { page, limit, search });
|
|
421
495
|
const transformedUsers = (result.data || []).map((user) => ({
|
|
422
496
|
id: user.id,
|
|
423
497
|
email: user.email,
|
|
@@ -438,7 +512,7 @@ function createRoutes(authConfig) {
|
|
|
438
512
|
try {
|
|
439
513
|
const page = parseInt(req.query.page) || 1;
|
|
440
514
|
const limit = parseInt(req.query.limit) || 20;
|
|
441
|
-
const sessions = await
|
|
515
|
+
const sessions = await getAuthData(authConfig, 'sessions', { page, limit });
|
|
442
516
|
res.json(sessions);
|
|
443
517
|
}
|
|
444
518
|
catch (error) {
|
|
@@ -448,7 +522,7 @@ function createRoutes(authConfig) {
|
|
|
448
522
|
});
|
|
449
523
|
router.get('/api/providers', async (req, res) => {
|
|
450
524
|
try {
|
|
451
|
-
const providers = await
|
|
525
|
+
const providers = await getAuthData(authConfig, 'providers');
|
|
452
526
|
res.json(providers);
|
|
453
527
|
}
|
|
454
528
|
catch (error) {
|
|
@@ -459,7 +533,7 @@ function createRoutes(authConfig) {
|
|
|
459
533
|
router.delete('/api/users/:id', async (req, res) => {
|
|
460
534
|
try {
|
|
461
535
|
const { id } = req.params;
|
|
462
|
-
await
|
|
536
|
+
await getAuthData(authConfig, 'deleteUser', { id });
|
|
463
537
|
res.json({ success: true });
|
|
464
538
|
}
|
|
465
539
|
catch (error) {
|
|
@@ -506,9 +580,9 @@ function createRoutes(authConfig) {
|
|
|
506
580
|
console.log('Falling back to regex extraction...');
|
|
507
581
|
// Fallback to regex extraction when import fails
|
|
508
582
|
try {
|
|
509
|
-
const { readFileSync } = await
|
|
583
|
+
const { readFileSync } = await import('fs');
|
|
510
584
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
511
|
-
const { extractBetterAuthConfig } = await
|
|
585
|
+
const { extractBetterAuthConfig } = await import('./config');
|
|
512
586
|
const config = extractBetterAuthConfig(content);
|
|
513
587
|
if (config && config.plugins) {
|
|
514
588
|
const pluginInfo = config.plugins.map((plugin) => ({
|
|
@@ -572,9 +646,9 @@ function createRoutes(authConfig) {
|
|
|
572
646
|
console.log('Falling back to regex extraction...');
|
|
573
647
|
// Fallback to regex extraction when import fails
|
|
574
648
|
try {
|
|
575
|
-
const { readFileSync } = await
|
|
649
|
+
const { readFileSync } = await import('fs');
|
|
576
650
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
577
|
-
const { extractBetterAuthConfig } = await
|
|
651
|
+
const { extractBetterAuthConfig } = await import('./config');
|
|
578
652
|
const config = extractBetterAuthConfig(content);
|
|
579
653
|
if (config && config.database) {
|
|
580
654
|
return res.json({
|
|
@@ -632,9 +706,9 @@ function createRoutes(authConfig) {
|
|
|
632
706
|
console.log('Falling back to regex extraction...');
|
|
633
707
|
// Fallback to regex extraction when import fails
|
|
634
708
|
try {
|
|
635
|
-
const { readFileSync } = await
|
|
709
|
+
const { readFileSync } = await import('fs');
|
|
636
710
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
637
|
-
const { extractBetterAuthConfig } = await
|
|
711
|
+
const { extractBetterAuthConfig } = await import('./config');
|
|
638
712
|
const config = extractBetterAuthConfig(content);
|
|
639
713
|
if (config && config.plugins) {
|
|
640
714
|
const organizationPlugin = config.plugins.find((plugin) => plugin.id === "organization");
|
|
@@ -666,7 +740,7 @@ function createRoutes(authConfig) {
|
|
|
666
740
|
try {
|
|
667
741
|
console.log('fetching invitations', req.params);
|
|
668
742
|
const { orgId } = req.params;
|
|
669
|
-
const adapter = await
|
|
743
|
+
const adapter = await getAuthAdapter();
|
|
670
744
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
671
745
|
try {
|
|
672
746
|
const invitations = await adapter.findMany({
|
|
@@ -704,7 +778,7 @@ function createRoutes(authConfig) {
|
|
|
704
778
|
router.get('/api/organizations/:orgId/members', async (req, res) => {
|
|
705
779
|
try {
|
|
706
780
|
const { orgId } = req.params;
|
|
707
|
-
const adapter = await
|
|
781
|
+
const adapter = await getAuthAdapter();
|
|
708
782
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
709
783
|
try {
|
|
710
784
|
const members = await adapter.findMany({
|
|
@@ -762,7 +836,7 @@ function createRoutes(authConfig) {
|
|
|
762
836
|
try {
|
|
763
837
|
const { orgId } = req.params;
|
|
764
838
|
const { count = 5 } = req.body;
|
|
765
|
-
const adapter = await
|
|
839
|
+
const adapter = await getAuthAdapter();
|
|
766
840
|
if (!adapter) {
|
|
767
841
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
768
842
|
}
|
|
@@ -837,7 +911,7 @@ function createRoutes(authConfig) {
|
|
|
837
911
|
try {
|
|
838
912
|
const { orgId } = req.params;
|
|
839
913
|
const { count = 3 } = req.body;
|
|
840
|
-
const adapter = await
|
|
914
|
+
const adapter = await getAuthAdapter();
|
|
841
915
|
if (!adapter) {
|
|
842
916
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
843
917
|
}
|
|
@@ -899,7 +973,7 @@ function createRoutes(authConfig) {
|
|
|
899
973
|
router.delete('/api/members/:id', async (req, res) => {
|
|
900
974
|
try {
|
|
901
975
|
const { id } = req.params;
|
|
902
|
-
const adapter = await
|
|
976
|
+
const adapter = await getAuthAdapter();
|
|
903
977
|
if (!adapter) {
|
|
904
978
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
905
979
|
}
|
|
@@ -920,7 +994,7 @@ function createRoutes(authConfig) {
|
|
|
920
994
|
router.post('/api/invitations/:id/resend', async (req, res) => {
|
|
921
995
|
try {
|
|
922
996
|
const { id } = req.params;
|
|
923
|
-
const adapter = await
|
|
997
|
+
const adapter = await getAuthAdapter();
|
|
924
998
|
if (!adapter) {
|
|
925
999
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
926
1000
|
}
|
|
@@ -945,7 +1019,7 @@ function createRoutes(authConfig) {
|
|
|
945
1019
|
router.delete('/api/invitations/:id', async (req, res) => {
|
|
946
1020
|
try {
|
|
947
1021
|
const { id } = req.params;
|
|
948
|
-
const adapter = await
|
|
1022
|
+
const adapter = await getAuthAdapter();
|
|
949
1023
|
if (!adapter) {
|
|
950
1024
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
951
1025
|
}
|
|
@@ -974,7 +1048,7 @@ function createRoutes(authConfig) {
|
|
|
974
1048
|
if (!inviterId) {
|
|
975
1049
|
return res.status(400).json({ error: 'Inviter ID is required' });
|
|
976
1050
|
}
|
|
977
|
-
const adapter = await
|
|
1051
|
+
const adapter = await getAuthAdapter();
|
|
978
1052
|
if (!adapter) {
|
|
979
1053
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
980
1054
|
}
|
|
@@ -1016,7 +1090,7 @@ function createRoutes(authConfig) {
|
|
|
1016
1090
|
router.get('/api/organizations/:orgId/teams', async (req, res) => {
|
|
1017
1091
|
try {
|
|
1018
1092
|
const { orgId } = req.params;
|
|
1019
|
-
const adapter = await
|
|
1093
|
+
const adapter = await getAuthAdapter();
|
|
1020
1094
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
1021
1095
|
try {
|
|
1022
1096
|
const teams = await adapter.findMany({
|
|
@@ -1061,7 +1135,7 @@ function createRoutes(authConfig) {
|
|
|
1061
1135
|
try {
|
|
1062
1136
|
const { orgId } = req.params;
|
|
1063
1137
|
const { name } = req.body;
|
|
1064
|
-
const adapter = await
|
|
1138
|
+
const adapter = await getAuthAdapter();
|
|
1065
1139
|
if (!adapter) {
|
|
1066
1140
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1067
1141
|
}
|
|
@@ -1098,7 +1172,7 @@ function createRoutes(authConfig) {
|
|
|
1098
1172
|
router.get('/api/teams/:id', async (req, res) => {
|
|
1099
1173
|
try {
|
|
1100
1174
|
const { id } = req.params;
|
|
1101
|
-
const adapter = await
|
|
1175
|
+
const adapter = await getAuthAdapter();
|
|
1102
1176
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
1103
1177
|
try {
|
|
1104
1178
|
const teams = await adapter.findMany({
|
|
@@ -1151,7 +1225,7 @@ function createRoutes(authConfig) {
|
|
|
1151
1225
|
router.get('/api/teams/:teamId/members', async (req, res) => {
|
|
1152
1226
|
try {
|
|
1153
1227
|
const { teamId } = req.params;
|
|
1154
|
-
const adapter = await
|
|
1228
|
+
const adapter = await getAuthAdapter();
|
|
1155
1229
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
1156
1230
|
try {
|
|
1157
1231
|
const teamMembers = await adapter.findMany({
|
|
@@ -1212,7 +1286,7 @@ function createRoutes(authConfig) {
|
|
|
1212
1286
|
if (!Array.isArray(userIds) || userIds.length === 0) {
|
|
1213
1287
|
return res.status(400).json({ error: 'userIds array is required' });
|
|
1214
1288
|
}
|
|
1215
|
-
const adapter = await
|
|
1289
|
+
const adapter = await getAuthAdapter();
|
|
1216
1290
|
if (!adapter || !adapter.create) {
|
|
1217
1291
|
return res.status(500).json({ error: 'Adapter not available' });
|
|
1218
1292
|
}
|
|
@@ -1252,7 +1326,7 @@ function createRoutes(authConfig) {
|
|
|
1252
1326
|
router.delete('/api/team-members/:id', async (req, res) => {
|
|
1253
1327
|
try {
|
|
1254
1328
|
const { id } = req.params;
|
|
1255
|
-
const adapter = await
|
|
1329
|
+
const adapter = await getAuthAdapter();
|
|
1256
1330
|
if (!adapter || !adapter.delete) {
|
|
1257
1331
|
return res.status(500).json({ error: 'Adapter not available' });
|
|
1258
1332
|
}
|
|
@@ -1271,7 +1345,7 @@ function createRoutes(authConfig) {
|
|
|
1271
1345
|
try {
|
|
1272
1346
|
const { id } = req.params;
|
|
1273
1347
|
const { name } = req.body;
|
|
1274
|
-
const adapter = await
|
|
1348
|
+
const adapter = await getAuthAdapter();
|
|
1275
1349
|
if (!adapter) {
|
|
1276
1350
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1277
1351
|
}
|
|
@@ -1301,7 +1375,7 @@ function createRoutes(authConfig) {
|
|
|
1301
1375
|
router.delete('/api/teams/:id', async (req, res) => {
|
|
1302
1376
|
try {
|
|
1303
1377
|
const { id } = req.params;
|
|
1304
|
-
const adapter = await
|
|
1378
|
+
const adapter = await getAuthAdapter();
|
|
1305
1379
|
if (!adapter) {
|
|
1306
1380
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1307
1381
|
}
|
|
@@ -1354,9 +1428,9 @@ function createRoutes(authConfig) {
|
|
|
1354
1428
|
console.log('Falling back to regex extraction...');
|
|
1355
1429
|
// Fallback to regex extraction when import fails
|
|
1356
1430
|
try {
|
|
1357
|
-
const { readFileSync } = await
|
|
1431
|
+
const { readFileSync } = await import('fs');
|
|
1358
1432
|
const content = readFileSync(authConfigPath, 'utf-8');
|
|
1359
|
-
const { extractBetterAuthConfig } = await
|
|
1433
|
+
const { extractBetterAuthConfig } = await import('./config');
|
|
1360
1434
|
const config = extractBetterAuthConfig(content);
|
|
1361
1435
|
if (config && config.plugins) {
|
|
1362
1436
|
const hasOrganizationPlugin = config.plugins.find((plugin) => plugin.id === "organization");
|
|
@@ -1390,7 +1464,7 @@ function createRoutes(authConfig) {
|
|
|
1390
1464
|
const limit = parseInt(req.query.limit) || 20;
|
|
1391
1465
|
const search = req.query.search;
|
|
1392
1466
|
try {
|
|
1393
|
-
const adapter = await
|
|
1467
|
+
const adapter = await getAuthAdapter();
|
|
1394
1468
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
1395
1469
|
const allOrganizations = await adapter.findMany({ model: 'organization' });
|
|
1396
1470
|
console.log('Found organizations via findMany:', allOrganizations?.length || 0);
|
|
@@ -1444,7 +1518,7 @@ function createRoutes(authConfig) {
|
|
|
1444
1518
|
});
|
|
1445
1519
|
router.post('/api/organizations', async (req, res) => {
|
|
1446
1520
|
try {
|
|
1447
|
-
const adapter = await
|
|
1521
|
+
const adapter = await getAuthAdapter();
|
|
1448
1522
|
if (!adapter) {
|
|
1449
1523
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1450
1524
|
}
|
|
@@ -1464,7 +1538,7 @@ function createRoutes(authConfig) {
|
|
|
1464
1538
|
try {
|
|
1465
1539
|
const { id } = req.params;
|
|
1466
1540
|
const orgData = req.body;
|
|
1467
|
-
const adapter = await
|
|
1541
|
+
const adapter = await getAuthAdapter();
|
|
1468
1542
|
if (!adapter) {
|
|
1469
1543
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1470
1544
|
}
|
|
@@ -1493,7 +1567,7 @@ function createRoutes(authConfig) {
|
|
|
1493
1567
|
router.get('/api/organizations/:id', async (req, res) => {
|
|
1494
1568
|
try {
|
|
1495
1569
|
const { id } = req.params;
|
|
1496
|
-
const adapter = await
|
|
1570
|
+
const adapter = await getAuthAdapter();
|
|
1497
1571
|
if (adapter && typeof adapter.findMany === 'function') {
|
|
1498
1572
|
const organizations = await adapter.findMany({ model: 'organization', limit: 10000 });
|
|
1499
1573
|
const organization = organizations?.find((org) => org.id === id);
|
|
@@ -1520,7 +1594,7 @@ function createRoutes(authConfig) {
|
|
|
1520
1594
|
router.delete('/api/organizations/:id', async (req, res) => {
|
|
1521
1595
|
try {
|
|
1522
1596
|
const { id } = req.params;
|
|
1523
|
-
const adapter = await
|
|
1597
|
+
const adapter = await getAuthAdapter();
|
|
1524
1598
|
if (!adapter) {
|
|
1525
1599
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1526
1600
|
}
|
|
@@ -1539,7 +1613,7 @@ function createRoutes(authConfig) {
|
|
|
1539
1613
|
});
|
|
1540
1614
|
router.post('/api/users', async (req, res) => {
|
|
1541
1615
|
try {
|
|
1542
|
-
const adapter = await
|
|
1616
|
+
const adapter = await getAuthAdapter();
|
|
1543
1617
|
if (!adapter) {
|
|
1544
1618
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1545
1619
|
}
|
|
@@ -1556,7 +1630,7 @@ function createRoutes(authConfig) {
|
|
|
1556
1630
|
try {
|
|
1557
1631
|
const { id } = req.params;
|
|
1558
1632
|
const userData = req.body;
|
|
1559
|
-
const updatedUser = await
|
|
1633
|
+
const updatedUser = await getAuthData(authConfig, 'updateUser', { id, userData });
|
|
1560
1634
|
res.json({ success: true, user: updatedUser });
|
|
1561
1635
|
}
|
|
1562
1636
|
catch (error) {
|
|
@@ -1567,7 +1641,7 @@ function createRoutes(authConfig) {
|
|
|
1567
1641
|
router.post('/api/seed/users', async (req, res) => {
|
|
1568
1642
|
try {
|
|
1569
1643
|
const { count = 1 } = req.body;
|
|
1570
|
-
const adapter = await
|
|
1644
|
+
const adapter = await getAuthAdapter();
|
|
1571
1645
|
console.log({ adapter });
|
|
1572
1646
|
if (!adapter) {
|
|
1573
1647
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
@@ -1578,7 +1652,7 @@ function createRoutes(authConfig) {
|
|
|
1578
1652
|
if (typeof adapter.createUser !== 'function') {
|
|
1579
1653
|
throw new Error('createUser method not available on adapter');
|
|
1580
1654
|
}
|
|
1581
|
-
const user = await
|
|
1655
|
+
const user = await createMockUser(adapter, i + 1);
|
|
1582
1656
|
results.push({
|
|
1583
1657
|
success: true,
|
|
1584
1658
|
user: {
|
|
@@ -1612,13 +1686,13 @@ function createRoutes(authConfig) {
|
|
|
1612
1686
|
router.post('/api/seed/sessions', async (req, res) => {
|
|
1613
1687
|
try {
|
|
1614
1688
|
const { count = 1 } = req.body;
|
|
1615
|
-
const adapter = await
|
|
1689
|
+
const adapter = await getAuthAdapter();
|
|
1616
1690
|
if (!adapter) {
|
|
1617
1691
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1618
1692
|
}
|
|
1619
1693
|
let user;
|
|
1620
1694
|
try {
|
|
1621
|
-
user = await
|
|
1695
|
+
user = await createMockUser(adapter, 1);
|
|
1622
1696
|
}
|
|
1623
1697
|
catch (error) {
|
|
1624
1698
|
return res.status(500).json({ error: 'Failed to create user for session' });
|
|
@@ -1629,7 +1703,7 @@ function createRoutes(authConfig) {
|
|
|
1629
1703
|
if (typeof adapter.createSession !== 'function') {
|
|
1630
1704
|
throw new Error('createSession method not available on adapter');
|
|
1631
1705
|
}
|
|
1632
|
-
const session = await
|
|
1706
|
+
const session = await createMockSession(adapter, user.id, i + 1);
|
|
1633
1707
|
results.push({
|
|
1634
1708
|
success: true,
|
|
1635
1709
|
session: {
|
|
@@ -1662,13 +1736,13 @@ function createRoutes(authConfig) {
|
|
|
1662
1736
|
router.post('/api/seed/accounts', async (req, res) => {
|
|
1663
1737
|
try {
|
|
1664
1738
|
const { count = 1 } = req.body;
|
|
1665
|
-
const adapter = await
|
|
1739
|
+
const adapter = await getAuthAdapter();
|
|
1666
1740
|
if (!adapter) {
|
|
1667
1741
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1668
1742
|
}
|
|
1669
1743
|
let user;
|
|
1670
1744
|
try {
|
|
1671
|
-
user = await
|
|
1745
|
+
user = await createMockUser(adapter, 1);
|
|
1672
1746
|
}
|
|
1673
1747
|
catch (error) {
|
|
1674
1748
|
return res.status(500).json({ error: 'Failed to create user for account' });
|
|
@@ -1679,7 +1753,7 @@ function createRoutes(authConfig) {
|
|
|
1679
1753
|
if (typeof adapter.createAccount !== 'function') {
|
|
1680
1754
|
throw new Error('createAccount method not available on adapter');
|
|
1681
1755
|
}
|
|
1682
|
-
const account = await
|
|
1756
|
+
const account = await createMockAccount(adapter, user.id, i + 1);
|
|
1683
1757
|
results.push({
|
|
1684
1758
|
success: true,
|
|
1685
1759
|
account: {
|
|
@@ -1713,7 +1787,7 @@ function createRoutes(authConfig) {
|
|
|
1713
1787
|
router.post('/api/seed/verifications', async (req, res) => {
|
|
1714
1788
|
try {
|
|
1715
1789
|
const { count = 1 } = req.body;
|
|
1716
|
-
const adapter = await
|
|
1790
|
+
const adapter = await getAuthAdapter();
|
|
1717
1791
|
if (!adapter) {
|
|
1718
1792
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1719
1793
|
}
|
|
@@ -1723,7 +1797,7 @@ function createRoutes(authConfig) {
|
|
|
1723
1797
|
if (typeof adapter.createVerification !== 'function') {
|
|
1724
1798
|
throw new Error('createVerification method not available on adapter');
|
|
1725
1799
|
}
|
|
1726
|
-
const verification = await
|
|
1800
|
+
const verification = await createMockVerification(adapter, `user${i + 1}@example.com`, i + 1);
|
|
1727
1801
|
results.push({
|
|
1728
1802
|
success: true,
|
|
1729
1803
|
verification: {
|
|
@@ -1756,7 +1830,7 @@ function createRoutes(authConfig) {
|
|
|
1756
1830
|
router.post('/api/seed/organizations', async (req, res) => {
|
|
1757
1831
|
try {
|
|
1758
1832
|
const { count = 1 } = req.body;
|
|
1759
|
-
const adapter = await
|
|
1833
|
+
const adapter = await getAuthAdapter();
|
|
1760
1834
|
if (!adapter) {
|
|
1761
1835
|
return res.status(500).json({ error: 'Auth adapter not available' });
|
|
1762
1836
|
}
|