@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/plugin-auth@4.0.3 build /home/runner/work/framework/framework/packages/plugins/plugin-auth
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
  ╵ ~~~~~~~~~
48
48
 
49
49
 
50
+ CJS dist/index.js 50.99 KB
51
+ CJS dist/index.js.map 104.52 KB
52
+ CJS ⚡️ Build success in 85ms
50
53
  [warn] ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
51
54
 
52
55
  package.json:13:6:
@@ -66,13 +69,10 @@
66
69
  ╵ ~~~~~~~~~
67
70
 
68
71
 
69
- CJS dist/index.js 48.18 KB
70
- CJS dist/index.js.map 99.34 KB
71
- CJS ⚡️ Build success in 86ms
72
- ESM dist/index.mjs 44.60 KB
73
- ESM dist/index.mjs.map 98.83 KB
74
- ESM ⚡️ Build success in 86ms
72
+ ESM dist/index.mjs 47.42 KB
73
+ ESM dist/index.mjs.map 104.01 KB
74
+ ESM ⚡️ Build success in 95ms
75
75
  DTS Build start
76
- DTS ⚡️ Build success in 5289ms
77
- DTS dist/index.d.mts 913.41 KB
78
- DTS dist/index.d.ts 913.41 KB
76
+ DTS ⚡️ Build success in 7023ms
77
+ DTS dist/index.d.mts 914.23 KB
78
+ DTS dist/index.d.ts 914.23 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [326b66b]
8
+ - @objectstack/spec@4.0.4
9
+ - @objectstack/core@4.0.4
10
+
3
11
  ## 4.0.3
4
12
 
5
13
  ### Patch Changes
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
- ...this.config.trustedOrigins?.length ? { trustedOrigins: this.config.trustedOrigins } : {},
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);