better-auth-studio 1.1.2-beta.15 → 1.1.2-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -23
- package/data/default-geo.json +1 -1
- package/dist/adapters/astro.d.ts +1 -1
- package/dist/adapters/astro.js +13 -13
- package/dist/adapters/elysia.d.ts +2 -2
- package/dist/adapters/elysia.js +13 -13
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +4 -4
- package/dist/adapters/hono.d.ts +2 -2
- package/dist/adapters/hono.js +12 -12
- package/dist/adapters/nextjs.d.ts +1 -1
- package/dist/adapters/nextjs.js +10 -10
- package/dist/adapters/nuxt.d.ts +1 -1
- package/dist/adapters/nuxt.js +22 -22
- package/dist/adapters/remix.d.ts +1 -1
- package/dist/adapters/remix.js +13 -13
- package/dist/adapters/solid-start.d.ts +1 -1
- package/dist/adapters/solid-start.js +13 -13
- package/dist/adapters/svelte-kit.d.ts +2 -2
- package/dist/adapters/svelte-kit.js +13 -13
- package/dist/adapters/tanstack-start.d.ts +1 -1
- package/dist/adapters/tanstack-start.js +13 -13
- package/dist/add-svelte-kit-env-modules.js +11 -11
- package/dist/auth-adapter.d.ts +1 -1
- package/dist/auth-adapter.js +96 -96
- package/dist/cli/commands/init.js +57 -57
- package/dist/cli.js +75 -75
- package/dist/config.d.ts +5 -5
- package/dist/config.js +37 -37
- package/dist/core/handler.d.ts +1 -1
- package/dist/core/handler.js +115 -115
- package/dist/data.d.ts +2 -2
- package/dist/data.js +60 -60
- package/dist/geo-service.js +78 -78
- package/dist/get-tsconfig-info.js +4 -4
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/providers/events/helpers.d.ts +2 -2
- package/dist/providers/events/helpers.js +156 -156
- package/dist/routes/api-router.d.ts +2 -2
- package/dist/routes/api-router.js +3 -3
- package/dist/routes.d.ts +4 -4
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +1272 -1272
- package/dist/routes.js.map +1 -1
- package/dist/studio.d.ts +3 -3
- package/dist/studio.js +64 -64
- package/dist/types/events.d.ts +7 -7
- package/dist/types/events.js +165 -165
- package/dist/types/handler.d.ts +5 -5
- package/dist/utils/auth-callbacks-injector.d.ts +2 -2
- package/dist/utils/auth-callbacks-injector.js +27 -27
- package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
- package/dist/utils/auth-callbacks-wrapper.js +117 -107
- package/dist/utils/database-detection.d.ts +1 -1
- package/dist/utils/database-detection.js +44 -44
- package/dist/utils/database-hook-injector.d.ts +3 -3
- package/dist/utils/database-hook-injector.js +135 -131
- package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
- package/dist/utils/email-otp-hooks-injector.js +104 -97
- package/dist/utils/event-ingestion.d.ts +5 -5
- package/dist/utils/event-ingestion.d.ts.map +1 -1
- package/dist/utils/event-ingestion.js +14 -16
- package/dist/utils/event-ingestion.js.map +1 -1
- package/dist/utils/hook-injector.d.ts +2 -2
- package/dist/utils/hook-injector.js +199 -199
- package/dist/utils/html-injector.d.ts +3 -3
- package/dist/utils/html-injector.js +37 -37
- package/dist/utils/org-hooks-injector.d.ts +3 -3
- package/dist/utils/org-hooks-injector.js +63 -63
- package/dist/utils/org-hooks-wrapper.d.ts +41 -35
- package/dist/utils/org-hooks-wrapper.js +778 -658
- package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
- package/dist/utils/organization-hooks-wrapper.js +325 -277
- package/dist/utils/package-json.js +11 -11
- package/dist/utils/paths.js +1 -1
- package/dist/utils/server-init.d.ts +1 -1
- package/dist/utils/server-init.js +25 -25
- package/dist/utils/session.js +12 -12
- package/dist/utils.js +24 -24
- package/package.json +26 -26
- package/scripts/download-geolite2.js +8 -8
- package/scripts/generate-default-db.js +324 -324
- package/scripts/postinstall.js +25 -25
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { dirname, join, resolve } from
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
/**
|
|
5
5
|
* Find the project root by looking for package.json files up the directory tree
|
|
6
6
|
* @param startDir - Directory to start searching from
|
|
@@ -8,9 +8,9 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
8
8
|
*/
|
|
9
9
|
function findProjectRoot(startDir) {
|
|
10
10
|
let currentDir = resolve(startDir);
|
|
11
|
-
const root = resolve(
|
|
11
|
+
const root = resolve("/");
|
|
12
12
|
while (currentDir !== root) {
|
|
13
|
-
const packageJsonPath = join(currentDir,
|
|
13
|
+
const packageJsonPath = join(currentDir, "package.json");
|
|
14
14
|
if (existsSync(packageJsonPath)) {
|
|
15
15
|
return currentDir;
|
|
16
16
|
}
|
|
@@ -28,17 +28,17 @@ export async function getPackageVersion(packageName, cwd) {
|
|
|
28
28
|
const searchDir = cwd || process.cwd();
|
|
29
29
|
try {
|
|
30
30
|
const projectRoot = findProjectRoot(searchDir);
|
|
31
|
-
const packageJsonPath = join(searchDir,
|
|
31
|
+
const packageJsonPath = join(searchDir, "package.json");
|
|
32
32
|
if (existsSync(packageJsonPath)) {
|
|
33
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath,
|
|
33
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
34
34
|
if (packageJson.dependencies?.[packageName]) {
|
|
35
|
-
return packageJson.dependencies[packageName].replace(/[\^~]/,
|
|
35
|
+
return packageJson.dependencies[packageName].replace(/[\^~]/, "");
|
|
36
36
|
}
|
|
37
37
|
if (packageJson.devDependencies?.[packageName]) {
|
|
38
|
-
return packageJson.devDependencies[packageName].replace(/[\^~]/,
|
|
38
|
+
return packageJson.devDependencies[packageName].replace(/[\^~]/, "");
|
|
39
39
|
}
|
|
40
40
|
if (packageJson.peerDependencies?.[packageName]) {
|
|
41
|
-
return packageJson.peerDependencies[packageName].replace(/[\^~]/,
|
|
41
|
+
return packageJson.peerDependencies[packageName].replace(/[\^~]/, "");
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
@@ -47,7 +47,7 @@ export async function getPackageVersion(packageName, cwd) {
|
|
|
47
47
|
paths: [projectRoot],
|
|
48
48
|
});
|
|
49
49
|
if (existsSync(packagePath)) {
|
|
50
|
-
const packageJson = JSON.parse(readFileSync(packagePath,
|
|
50
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
|
|
51
51
|
return packageJson.version;
|
|
52
52
|
}
|
|
53
53
|
}
|
package/dist/utils/paths.js
CHANGED
|
@@ -8,33 +8,33 @@ let initializationAttempted = false;
|
|
|
8
8
|
* This should be called at server startup, before any auth requests
|
|
9
9
|
*/
|
|
10
10
|
export function initializeOnServerStart(baseUrl, basePath) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
console.log("PINGGEDD");
|
|
12
|
+
if (initializationAttempted) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
initializationAttempted = true;
|
|
16
|
+
// Use setImmediate to ensure this runs after the event loop starts
|
|
17
|
+
// but before any requests are processed
|
|
18
|
+
setImmediate(async () => {
|
|
19
|
+
try {
|
|
20
|
+
const url =
|
|
21
|
+
baseUrl || process.env.BETTER_AUTH_URL || process.env.AUTH_URL || "http://localhost:3000";
|
|
22
|
+
const path = basePath || process.env.BETTER_AUTH_STUDIO_PATH || "/api/studio";
|
|
23
|
+
const fullUrl = `${url}${path}`;
|
|
24
|
+
await fetch(fullUrl, {
|
|
25
|
+
method: "GET",
|
|
26
|
+
headers: { "user-agent": "better-auth-studio-server-init" },
|
|
27
|
+
}).catch(() => {
|
|
28
|
+
// Silently fail - initialization will happen on first real request
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// Silently fail - initialization will happen on first real request
|
|
14
32
|
}
|
|
15
|
-
|
|
16
|
-
// Use setImmediate to ensure this runs after the event loop starts
|
|
17
|
-
// but before any requests are processed
|
|
18
|
-
setImmediate(async () => {
|
|
19
|
-
try {
|
|
20
|
-
const url = baseUrl || process.env.BETTER_AUTH_URL || process.env.AUTH_URL || 'http://localhost:3000';
|
|
21
|
-
const path = basePath || process.env.BETTER_AUTH_STUDIO_PATH || '/api/studio';
|
|
22
|
-
const fullUrl = `${url}${path}`;
|
|
23
|
-
await fetch(fullUrl, {
|
|
24
|
-
method: 'GET',
|
|
25
|
-
headers: { 'user-agent': 'better-auth-studio-server-init' },
|
|
26
|
-
}).catch(() => {
|
|
27
|
-
// Silently fail - initialization will happen on first real request
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
// Silently fail - initialization will happen on first real request
|
|
32
|
-
}
|
|
33
|
-
});
|
|
33
|
+
});
|
|
34
34
|
}
|
|
35
35
|
// @ts-ignore
|
|
36
36
|
// Auto-initialize when module is imported (if in server environment)
|
|
37
|
-
if (typeof window ===
|
|
38
|
-
|
|
37
|
+
if (typeof window === "undefined" && typeof process !== "undefined") {
|
|
38
|
+
initializeOnServerStart();
|
|
39
39
|
}
|
|
40
|
-
//# sourceMappingURL=server-init.js.map
|
|
40
|
+
//# sourceMappingURL=server-init.js.map
|
package/dist/utils/session.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHmac, randomBytes } from
|
|
2
|
-
const ALGORITHM =
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHmac, randomBytes } from "crypto";
|
|
2
|
+
const ALGORITHM = "aes-256-gcm";
|
|
3
3
|
const IV_LENGTH = 16;
|
|
4
4
|
const AUTH_TAG_LENGTH = 16;
|
|
5
5
|
function deriveKey(secret) {
|
|
6
|
-
return createHmac(
|
|
6
|
+
return createHmac("sha256", secret).update("studio-session-key").digest();
|
|
7
7
|
}
|
|
8
8
|
export function encryptSession(session, secret) {
|
|
9
9
|
const key = deriveKey(secret);
|
|
10
10
|
const iv = randomBytes(IV_LENGTH);
|
|
11
11
|
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
12
12
|
const data = JSON.stringify(session);
|
|
13
|
-
const encrypted = Buffer.concat([cipher.update(data,
|
|
13
|
+
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
14
14
|
const authTag = cipher.getAuthTag();
|
|
15
15
|
const combined = Buffer.concat([iv, authTag, encrypted]);
|
|
16
|
-
return combined.toString(
|
|
16
|
+
return combined.toString("base64url");
|
|
17
17
|
}
|
|
18
18
|
export function decryptSession(token, secret) {
|
|
19
19
|
try {
|
|
20
20
|
const key = deriveKey(secret);
|
|
21
|
-
const combined = Buffer.from(token,
|
|
21
|
+
const combined = Buffer.from(token, "base64url");
|
|
22
22
|
const iv = combined.subarray(0, IV_LENGTH);
|
|
23
23
|
const authTag = combined.subarray(IV_LENGTH, IV_LENGTH + AUTH_TAG_LENGTH);
|
|
24
24
|
const encrypted = combined.subarray(IV_LENGTH + AUTH_TAG_LENGTH);
|
|
25
25
|
const decipher = createDecipheriv(ALGORITHM, key, iv);
|
|
26
26
|
decipher.setAuthTag(authTag);
|
|
27
27
|
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
28
|
-
return JSON.parse(decrypted.toString(
|
|
28
|
+
return JSON.parse(decrypted.toString("utf8"));
|
|
29
29
|
}
|
|
30
30
|
catch {
|
|
31
31
|
return null;
|
|
@@ -45,14 +45,14 @@ export function createStudioSession(user, durationMs = 7 * 24 * 60 * 60 * 1000)
|
|
|
45
45
|
return {
|
|
46
46
|
userId: user.id,
|
|
47
47
|
email: user.email.length > maxEmailLength ? user.email.substring(0, maxEmailLength) : user.email,
|
|
48
|
-
name: (user.name ||
|
|
49
|
-
? (user.name ||
|
|
50
|
-
: user.name ||
|
|
51
|
-
role: user.role ||
|
|
48
|
+
name: (user.name || "").length > maxNameLength
|
|
49
|
+
? (user.name || "").substring(0, maxNameLength)
|
|
50
|
+
: user.name || "",
|
|
51
|
+
role: user.role || "user",
|
|
52
52
|
// Don't store image in session to reduce cookie size - it can be fetched from user data if needed
|
|
53
53
|
issuedAt: Date.now(),
|
|
54
54
|
expiresAt: Date.now() + durationMs,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
export const STUDIO_COOKIE_NAME =
|
|
57
|
+
export const STUDIO_COOKIE_NAME = "better_auth_studio_session";
|
|
58
58
|
//# sourceMappingURL=session.js.map
|
package/dist/utils.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
export const possibleConfigFiles = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
"auth.ts",
|
|
3
|
+
"auth.js",
|
|
4
|
+
"app/auth.ts",
|
|
5
|
+
"app/auth.js",
|
|
6
|
+
"apps/auth.ts",
|
|
7
|
+
"apps/auth.js",
|
|
8
|
+
"server/auth.ts",
|
|
9
|
+
"server/auth.js",
|
|
10
|
+
"src/auth.ts",
|
|
11
|
+
"src/auth.js",
|
|
12
|
+
"lib/auth.ts",
|
|
13
|
+
"utils/auth.ts",
|
|
14
|
+
"utils/auth.js",
|
|
15
|
+
"utils/auth.server.ts",
|
|
16
|
+
"utils/auth.server.js",
|
|
17
|
+
"utils/lib/auth.ts",
|
|
18
|
+
"utils/lib/auth.js",
|
|
19
|
+
"utils/lib/auth.server.ts",
|
|
20
|
+
"utils/lib/auth.server.js",
|
|
21
|
+
"lib/auth.js",
|
|
22
|
+
"better-auth.config.ts",
|
|
23
|
+
"better-auth.config.js",
|
|
24
|
+
"auth.config.ts",
|
|
25
|
+
"auth.config.js",
|
|
26
26
|
];
|
|
27
27
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth-studio",
|
|
3
|
-
"version": "1.1.2-beta.
|
|
3
|
+
"version": "1.1.2-beta.16",
|
|
4
4
|
"description": "Studio for Better Auth",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"admin",
|
|
7
|
+
"authentication",
|
|
8
|
+
"better-auth",
|
|
9
|
+
"dashboard",
|
|
10
|
+
"gui",
|
|
11
|
+
"studio"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "kinfish",
|
|
7
15
|
"bin": {
|
|
8
16
|
"better-auth-studio": "./dist/cli.js"
|
|
9
17
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"README.md",
|
|
20
|
+
"data/default-geo.json",
|
|
21
|
+
"dist/",
|
|
22
|
+
"public/",
|
|
23
|
+
"scripts/"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "dist/index.js",
|
|
10
27
|
"exports": {
|
|
11
28
|
".": "./dist/index.js",
|
|
12
29
|
"./express": "./dist/adapters/express.js",
|
|
@@ -33,9 +50,9 @@
|
|
|
33
50
|
"frontend:dev": "cd frontend && pnpm run dev",
|
|
34
51
|
"frontend:build": "cd frontend && pnpm run build",
|
|
35
52
|
"frontend:preview": "cd frontend && pnpm run preview",
|
|
36
|
-
"lint": "
|
|
37
|
-
"lint:fix": "
|
|
38
|
-
"format": "
|
|
53
|
+
"lint": "oxfmt --check .",
|
|
54
|
+
"lint:fix": "oxfmt .",
|
|
55
|
+
"format": "oxfmt format --write .",
|
|
39
56
|
"type-check": "tsc --noEmit",
|
|
40
57
|
"test": "vitest",
|
|
41
58
|
"test:watch": "vitest --watch",
|
|
@@ -47,16 +64,6 @@
|
|
|
47
64
|
"release:canary": "pnpm build && bumpp --preid canary --no-commit --no-tag --no-push && pnpm publish --access public --tag canary --no-git-checks",
|
|
48
65
|
"bump": "bumpp"
|
|
49
66
|
},
|
|
50
|
-
"keywords": [
|
|
51
|
-
"better-auth",
|
|
52
|
-
"studio",
|
|
53
|
-
"dashboard",
|
|
54
|
-
"authentication",
|
|
55
|
-
"gui",
|
|
56
|
-
"admin"
|
|
57
|
-
],
|
|
58
|
-
"author": "kinfish",
|
|
59
|
-
"license": "MIT",
|
|
60
67
|
"dependencies": {
|
|
61
68
|
"@babel/preset-react": "^7.27.1",
|
|
62
69
|
"@babel/preset-typescript": "^7.27.1",
|
|
@@ -81,12 +88,12 @@
|
|
|
81
88
|
"ws": "^8.14.2"
|
|
82
89
|
},
|
|
83
90
|
"devDependencies": {
|
|
84
|
-
"@biomejs/biome": "^2.2.4",
|
|
85
91
|
"@types/cors": "^2.8.17",
|
|
86
92
|
"@types/express": "^4.17.21",
|
|
87
93
|
"@types/node": "^20.10.0",
|
|
88
94
|
"@types/supertest": "^6.0.2",
|
|
89
95
|
"@types/ws": "^8.5.10",
|
|
96
|
+
"oxfmt": "^0.26.0",
|
|
90
97
|
"supertest": "^7.1.4",
|
|
91
98
|
"tsx": "^4.6.0",
|
|
92
99
|
"typescript": "^5.3.2",
|
|
@@ -102,12 +109,5 @@
|
|
|
102
109
|
"devalue": ">=5.6.2",
|
|
103
110
|
"@sveltejs/kit": ">=2.49.5"
|
|
104
111
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
"dist/",
|
|
108
|
-
"public/",
|
|
109
|
-
"data/default-geo.json",
|
|
110
|
-
"scripts/",
|
|
111
|
-
"README.md"
|
|
112
|
-
]
|
|
113
|
-
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const https = require(
|
|
4
|
-
const fs = require(
|
|
5
|
-
const path = require(
|
|
3
|
+
const https = require("node:https");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
6
|
|
|
7
7
|
const GEO_DB_URL =
|
|
8
|
-
|
|
9
|
-
const OUTPUT_PATH = path.join(__dirname,
|
|
8
|
+
"https://github.com/P3TERX/GeoLite.mmdb/releases/download/2024.08.13/GeoLite2-City.mmdb";
|
|
9
|
+
const OUTPUT_PATH = path.join(__dirname, "..", "data", "GeoLite2-City.mmdb");
|
|
10
10
|
|
|
11
11
|
const dataDir = path.dirname(OUTPUT_PATH);
|
|
12
12
|
if (!fs.existsSync(dataDir)) {
|
|
@@ -20,16 +20,16 @@ https
|
|
|
20
20
|
if (response.statusCode === 200) {
|
|
21
21
|
response.pipe(file);
|
|
22
22
|
|
|
23
|
-
file.on(
|
|
23
|
+
file.on("finish", () => {
|
|
24
24
|
file.close();
|
|
25
25
|
|
|
26
26
|
const _stats = fs.statSync(OUTPUT_PATH);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
file.on(
|
|
29
|
+
file.on("error", (_err) => {
|
|
30
30
|
fs.unlink(OUTPUT_PATH, () => {}); // Delete the file on error
|
|
31
31
|
});
|
|
32
32
|
} else {
|
|
33
33
|
}
|
|
34
34
|
})
|
|
35
|
-
.on(
|
|
35
|
+
.on("error", (_err) => {});
|