@objectstack/plugin-auth 4.0.3 → 4.0.4
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/auth-manager.test.ts +129 -4
- package/src/auth-manager.ts +83 -2
- package/src/auth-plugin.test.ts +6 -3
- package/src/auth-plugin.ts +22 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/plugin-auth@4.0.
|
|
2
|
+
> @objectstack/plugin-auth@4.0.4 build /home/runner/work/framework/framework/packages/plugins/plugin-auth
|
|
3
3
|
> tsup --config ../../../tsup.config.ts
|
|
4
4
|
|
|
5
5
|
▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
|
|
@@ -47,6 +47,9 @@
|
|
|
47
47
|
╵ [32m~~~~~~~~~[0m
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
[32mCJS[39m [1mdist/index.js [22m[32m50.99 KB[39m
|
|
51
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m104.52 KB[39m
|
|
52
|
+
[32mCJS[39m ⚡️ Build success in 85ms
|
|
50
53
|
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
51
54
|
|
|
52
55
|
package.json:13:6:
|
|
@@ -66,13 +69,10 @@
|
|
|
66
69
|
╵ [32m~~~~~~~~~[0m
|
|
67
70
|
|
|
68
71
|
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m44.60 KB[39m
|
|
73
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[32m98.83 KB[39m
|
|
74
|
-
[32mESM[39m ⚡️ Build success in 86ms
|
|
72
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m47.42 KB[39m
|
|
73
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m104.01 KB[39m
|
|
74
|
+
[32mESM[39m ⚡️ Build success in 95ms
|
|
75
75
|
[34mDTS[39m Build start
|
|
76
|
-
[32mDTS[39m ⚡️ Build success in
|
|
77
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
78
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
76
|
+
[32mDTS[39m ⚡️ Build success in 7023ms
|
|
77
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m914.23 KB[39m
|
|
78
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m914.23 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -2286,6 +2286,33 @@ declare class AuthManager {
|
|
|
2286
2286
|
data: Record<string, any>;
|
|
2287
2287
|
} | null>;
|
|
2288
2288
|
}>>;
|
|
2289
|
+
/**
|
|
2290
|
+
* Get public authentication configuration
|
|
2291
|
+
* Returns safe, non-sensitive configuration that can be exposed to the frontend
|
|
2292
|
+
*
|
|
2293
|
+
* This allows the frontend to discover:
|
|
2294
|
+
* - Which social/OAuth providers are available
|
|
2295
|
+
* - Whether email/password login is enabled
|
|
2296
|
+
* - Which advanced features are enabled (2FA, magic links, etc.)
|
|
2297
|
+
*/
|
|
2298
|
+
getPublicConfig(): {
|
|
2299
|
+
emailPassword: {
|
|
2300
|
+
enabled: boolean;
|
|
2301
|
+
disableSignUp: boolean;
|
|
2302
|
+
requireEmailVerification: boolean;
|
|
2303
|
+
};
|
|
2304
|
+
socialProviders: {
|
|
2305
|
+
id: string;
|
|
2306
|
+
name: string;
|
|
2307
|
+
enabled: boolean;
|
|
2308
|
+
}[];
|
|
2309
|
+
features: {
|
|
2310
|
+
twoFactor: boolean;
|
|
2311
|
+
passkeys: boolean;
|
|
2312
|
+
magicLink: boolean;
|
|
2313
|
+
organization: boolean;
|
|
2314
|
+
};
|
|
2315
|
+
};
|
|
2289
2316
|
}
|
|
2290
2317
|
|
|
2291
2318
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2286,6 +2286,33 @@ declare class AuthManager {
|
|
|
2286
2286
|
data: Record<string, any>;
|
|
2287
2287
|
} | null>;
|
|
2288
2288
|
}>>;
|
|
2289
|
+
/**
|
|
2290
|
+
* Get public authentication configuration
|
|
2291
|
+
* Returns safe, non-sensitive configuration that can be exposed to the frontend
|
|
2292
|
+
*
|
|
2293
|
+
* This allows the frontend to discover:
|
|
2294
|
+
* - Which social/OAuth providers are available
|
|
2295
|
+
* - Whether email/password login is enabled
|
|
2296
|
+
* - Which advanced features are enabled (2FA, magic links, etc.)
|
|
2297
|
+
*/
|
|
2298
|
+
getPublicConfig(): {
|
|
2299
|
+
emailPassword: {
|
|
2300
|
+
enabled: boolean;
|
|
2301
|
+
disableSignUp: boolean;
|
|
2302
|
+
requireEmailVerification: boolean;
|
|
2303
|
+
};
|
|
2304
|
+
socialProviders: {
|
|
2305
|
+
id: string;
|
|
2306
|
+
name: string;
|
|
2307
|
+
enabled: boolean;
|
|
2308
|
+
}[];
|
|
2309
|
+
features: {
|
|
2310
|
+
twoFactor: boolean;
|
|
2311
|
+
passkeys: boolean;
|
|
2312
|
+
magicLink: boolean;
|
|
2313
|
+
organization: boolean;
|
|
2314
|
+
};
|
|
2315
|
+
};
|
|
2289
2316
|
}
|
|
2290
2317
|
|
|
2291
2318
|
/**
|
package/dist/index.js
CHANGED
|
@@ -433,7 +433,20 @@ var AuthManager = class {
|
|
|
433
433
|
// better-auth plugins — registered based on AuthPluginConfig flags
|
|
434
434
|
plugins: this.buildPluginList(),
|
|
435
435
|
// Trusted origins for CSRF protection (supports wildcards like "https://*.example.com")
|
|
436
|
-
|
|
436
|
+
// Auto-includes origins from CORS_ORIGIN env var so CORS and CSRF stay in sync.
|
|
437
|
+
...(() => {
|
|
438
|
+
const origins = [...this.config.trustedOrigins || []];
|
|
439
|
+
const corsOrigin = process.env.CORS_ORIGIN;
|
|
440
|
+
if (corsOrigin && corsOrigin !== "*") {
|
|
441
|
+
corsOrigin.split(",").map((s) => s.trim()).filter(Boolean).forEach((o) => {
|
|
442
|
+
if (!origins.includes(o)) origins.push(o);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
if (!origins.length && (!corsOrigin || corsOrigin === "*")) {
|
|
446
|
+
origins.push("http://localhost:*");
|
|
447
|
+
}
|
|
448
|
+
return origins.length ? { trustedOrigins: origins } : {};
|
|
449
|
+
})(),
|
|
437
450
|
// Advanced options (cross-subdomain cookies, secure cookies, CSRF, etc.)
|
|
438
451
|
...this.config.advanced ? {
|
|
439
452
|
advanced: {
|
|
@@ -569,6 +582,59 @@ var AuthManager = class {
|
|
|
569
582
|
get api() {
|
|
570
583
|
return this.getOrCreateAuth().api;
|
|
571
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* Get public authentication configuration
|
|
587
|
+
* Returns safe, non-sensitive configuration that can be exposed to the frontend
|
|
588
|
+
*
|
|
589
|
+
* This allows the frontend to discover:
|
|
590
|
+
* - Which social/OAuth providers are available
|
|
591
|
+
* - Whether email/password login is enabled
|
|
592
|
+
* - Which advanced features are enabled (2FA, magic links, etc.)
|
|
593
|
+
*/
|
|
594
|
+
getPublicConfig() {
|
|
595
|
+
const socialProviders = [];
|
|
596
|
+
if (this.config.socialProviders) {
|
|
597
|
+
for (const [id, providerConfig] of Object.entries(this.config.socialProviders)) {
|
|
598
|
+
if (providerConfig.enabled !== false) {
|
|
599
|
+
const nameMap = {
|
|
600
|
+
google: "Google",
|
|
601
|
+
github: "GitHub",
|
|
602
|
+
microsoft: "Microsoft",
|
|
603
|
+
apple: "Apple",
|
|
604
|
+
facebook: "Facebook",
|
|
605
|
+
twitter: "Twitter",
|
|
606
|
+
discord: "Discord",
|
|
607
|
+
gitlab: "GitLab",
|
|
608
|
+
linkedin: "LinkedIn"
|
|
609
|
+
};
|
|
610
|
+
socialProviders.push({
|
|
611
|
+
id,
|
|
612
|
+
name: nameMap[id] || id.charAt(0).toUpperCase() + id.slice(1),
|
|
613
|
+
enabled: true
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
const emailPasswordConfig = this.config.emailAndPassword ?? {};
|
|
619
|
+
const emailPassword = {
|
|
620
|
+
enabled: emailPasswordConfig.enabled !== false,
|
|
621
|
+
// Default to true
|
|
622
|
+
disableSignUp: emailPasswordConfig.disableSignUp ?? false,
|
|
623
|
+
requireEmailVerification: emailPasswordConfig.requireEmailVerification ?? false
|
|
624
|
+
};
|
|
625
|
+
const pluginConfig = this.config.plugins ?? {};
|
|
626
|
+
const features = {
|
|
627
|
+
twoFactor: pluginConfig.twoFactor ?? false,
|
|
628
|
+
passkeys: pluginConfig.passkeys ?? false,
|
|
629
|
+
magicLink: pluginConfig.magicLink ?? false,
|
|
630
|
+
organization: pluginConfig.organization ?? false
|
|
631
|
+
};
|
|
632
|
+
return {
|
|
633
|
+
emailPassword,
|
|
634
|
+
socialProviders,
|
|
635
|
+
features
|
|
636
|
+
};
|
|
637
|
+
}
|
|
572
638
|
};
|
|
573
639
|
|
|
574
640
|
// src/objects/sys-user.object.ts
|
|
@@ -1486,6 +1552,25 @@ var AuthPlugin = class {
|
|
|
1486
1552
|
);
|
|
1487
1553
|
}
|
|
1488
1554
|
const rawApp = httpServer.getRawApp();
|
|
1555
|
+
rawApp.get(`${basePath}/config`, async (c) => {
|
|
1556
|
+
try {
|
|
1557
|
+
const config = this.authManager.getPublicConfig();
|
|
1558
|
+
return c.json({
|
|
1559
|
+
success: true,
|
|
1560
|
+
data: config
|
|
1561
|
+
});
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1564
|
+
ctx.logger.error("Auth config error:", err);
|
|
1565
|
+
return c.json({
|
|
1566
|
+
success: false,
|
|
1567
|
+
error: {
|
|
1568
|
+
code: "auth_config_error",
|
|
1569
|
+
message: err.message
|
|
1570
|
+
}
|
|
1571
|
+
}, 500);
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1489
1574
|
rawApp.all(`${basePath}/*`, async (c) => {
|
|
1490
1575
|
try {
|
|
1491
1576
|
const response = await this.authManager.handleRequest(c.req.raw);
|