@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/dist/index.mjs CHANGED
@@ -372,7 +372,20 @@ var AuthManager = class {
372
372
  // better-auth plugins — registered based on AuthPluginConfig flags
373
373
  plugins: this.buildPluginList(),
374
374
  // Trusted origins for CSRF protection (supports wildcards like "https://*.example.com")
375
- ...this.config.trustedOrigins?.length ? { trustedOrigins: this.config.trustedOrigins } : {},
375
+ // Auto-includes origins from CORS_ORIGIN env var so CORS and CSRF stay in sync.
376
+ ...(() => {
377
+ const origins = [...this.config.trustedOrigins || []];
378
+ const corsOrigin = process.env.CORS_ORIGIN;
379
+ if (corsOrigin && corsOrigin !== "*") {
380
+ corsOrigin.split(",").map((s) => s.trim()).filter(Boolean).forEach((o) => {
381
+ if (!origins.includes(o)) origins.push(o);
382
+ });
383
+ }
384
+ if (!origins.length && (!corsOrigin || corsOrigin === "*")) {
385
+ origins.push("http://localhost:*");
386
+ }
387
+ return origins.length ? { trustedOrigins: origins } : {};
388
+ })(),
376
389
  // Advanced options (cross-subdomain cookies, secure cookies, CSRF, etc.)
377
390
  ...this.config.advanced ? {
378
391
  advanced: {
@@ -508,6 +521,59 @@ var AuthManager = class {
508
521
  get api() {
509
522
  return this.getOrCreateAuth().api;
510
523
  }
524
+ /**
525
+ * Get public authentication configuration
526
+ * Returns safe, non-sensitive configuration that can be exposed to the frontend
527
+ *
528
+ * This allows the frontend to discover:
529
+ * - Which social/OAuth providers are available
530
+ * - Whether email/password login is enabled
531
+ * - Which advanced features are enabled (2FA, magic links, etc.)
532
+ */
533
+ getPublicConfig() {
534
+ const socialProviders = [];
535
+ if (this.config.socialProviders) {
536
+ for (const [id, providerConfig] of Object.entries(this.config.socialProviders)) {
537
+ if (providerConfig.enabled !== false) {
538
+ const nameMap = {
539
+ google: "Google",
540
+ github: "GitHub",
541
+ microsoft: "Microsoft",
542
+ apple: "Apple",
543
+ facebook: "Facebook",
544
+ twitter: "Twitter",
545
+ discord: "Discord",
546
+ gitlab: "GitLab",
547
+ linkedin: "LinkedIn"
548
+ };
549
+ socialProviders.push({
550
+ id,
551
+ name: nameMap[id] || id.charAt(0).toUpperCase() + id.slice(1),
552
+ enabled: true
553
+ });
554
+ }
555
+ }
556
+ }
557
+ const emailPasswordConfig = this.config.emailAndPassword ?? {};
558
+ const emailPassword = {
559
+ enabled: emailPasswordConfig.enabled !== false,
560
+ // Default to true
561
+ disableSignUp: emailPasswordConfig.disableSignUp ?? false,
562
+ requireEmailVerification: emailPasswordConfig.requireEmailVerification ?? false
563
+ };
564
+ const pluginConfig = this.config.plugins ?? {};
565
+ const features = {
566
+ twoFactor: pluginConfig.twoFactor ?? false,
567
+ passkeys: pluginConfig.passkeys ?? false,
568
+ magicLink: pluginConfig.magicLink ?? false,
569
+ organization: pluginConfig.organization ?? false
570
+ };
571
+ return {
572
+ emailPassword,
573
+ socialProviders,
574
+ features
575
+ };
576
+ }
511
577
  };
512
578
 
513
579
  // src/objects/sys-user.object.ts
@@ -1425,6 +1491,25 @@ var AuthPlugin = class {
1425
1491
  );
1426
1492
  }
1427
1493
  const rawApp = httpServer.getRawApp();
1494
+ rawApp.get(`${basePath}/config`, async (c) => {
1495
+ try {
1496
+ const config = this.authManager.getPublicConfig();
1497
+ return c.json({
1498
+ success: true,
1499
+ data: config
1500
+ });
1501
+ } catch (error) {
1502
+ const err = error instanceof Error ? error : new Error(String(error));
1503
+ ctx.logger.error("Auth config error:", err);
1504
+ return c.json({
1505
+ success: false,
1506
+ error: {
1507
+ code: "auth_config_error",
1508
+ message: err.message
1509
+ }
1510
+ }, 500);
1511
+ }
1512
+ });
1428
1513
  rawApp.all(`${basePath}/*`, async (c) => {
1429
1514
  try {
1430
1515
  const response = await this.authManager.handleRequest(c.req.raw);