@nextsparkjs/core 0.1.0-beta.100 → 0.1.0-beta.101

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.
Files changed (75) hide show
  1. package/dist/components/auth/forms/LoginForm.d.ts.map +1 -1
  2. package/dist/components/auth/forms/LoginForm.js +15 -10
  3. package/dist/components/auth/forms/SignupForm.d.ts.map +1 -1
  4. package/dist/components/auth/forms/SignupForm.js +27 -24
  5. package/dist/components/auth/pages/AuthErrorPage.d.ts +2 -0
  6. package/dist/components/auth/pages/AuthErrorPage.d.ts.map +1 -0
  7. package/dist/components/auth/pages/AuthErrorPage.js +44 -0
  8. package/dist/lib/auth/registration-guard-plugin.d.ts +14 -0
  9. package/dist/lib/auth/registration-guard-plugin.d.ts.map +1 -0
  10. package/dist/lib/auth/registration-guard-plugin.js +37 -0
  11. package/dist/lib/auth/registration-helpers.d.ts +65 -0
  12. package/dist/lib/auth/registration-helpers.d.ts.map +1 -0
  13. package/dist/lib/auth/registration-helpers.js +51 -0
  14. package/dist/lib/auth.d.ts.map +1 -1
  15. package/dist/lib/auth.js +54 -1
  16. package/dist/lib/billing/config-types.d.ts +5 -0
  17. package/dist/lib/billing/config-types.d.ts.map +1 -1
  18. package/dist/lib/billing/gateways/factory.d.ts +25 -0
  19. package/dist/lib/billing/gateways/factory.d.ts.map +1 -0
  20. package/dist/lib/billing/gateways/factory.js +34 -0
  21. package/dist/lib/billing/gateways/interface.d.ts +20 -0
  22. package/dist/lib/billing/gateways/interface.d.ts.map +1 -0
  23. package/dist/lib/billing/gateways/polar.d.ts +47 -0
  24. package/dist/lib/billing/gateways/polar.d.ts.map +1 -0
  25. package/dist/lib/billing/gateways/polar.js +150 -0
  26. package/dist/lib/billing/gateways/stripe.d.ts +40 -65
  27. package/dist/lib/billing/gateways/stripe.d.ts.map +1 -1
  28. package/dist/lib/billing/gateways/stripe.js +134 -62
  29. package/dist/lib/billing/gateways/types.d.ts +52 -0
  30. package/dist/lib/billing/gateways/types.d.ts.map +1 -0
  31. package/dist/lib/billing/gateways/types.js +0 -0
  32. package/dist/lib/billing/types.d.ts +1 -1
  33. package/dist/lib/billing/types.d.ts.map +1 -1
  34. package/dist/lib/config/app.config.d.ts.map +1 -1
  35. package/dist/lib/config/app.config.js +24 -0
  36. package/dist/lib/config/config-sync.d.ts +15 -0
  37. package/dist/lib/config/config-sync.d.ts.map +1 -1
  38. package/dist/lib/config/config-sync.js +15 -0
  39. package/dist/lib/config/types.d.ts +67 -0
  40. package/dist/lib/config/types.d.ts.map +1 -1
  41. package/dist/lib/email/factory.d.ts.map +1 -1
  42. package/dist/lib/email/factory.js +0 -3
  43. package/dist/lib/media/utils.d.ts.map +1 -1
  44. package/dist/lib/services/plan.service.d.ts +6 -3
  45. package/dist/lib/services/plan.service.d.ts.map +1 -1
  46. package/dist/lib/services/plan.service.js +13 -4
  47. package/dist/lib/services/subscription.service.js +4 -4
  48. package/dist/lib/services/team.service.d.ts.map +1 -1
  49. package/dist/lib/services/team.service.js +1 -0
  50. package/dist/messages/en/auth.json +11 -0
  51. package/dist/messages/en/index.d.ts +11 -0
  52. package/dist/messages/en/index.d.ts.map +1 -1
  53. package/dist/messages/es/auth.json +11 -0
  54. package/dist/messages/es/index.d.ts +11 -0
  55. package/dist/messages/es/index.d.ts.map +1 -1
  56. package/dist/migrations/090_sample_data.sql +1 -1
  57. package/dist/styles/classes.json +1 -1
  58. package/dist/templates/app/(auth)/auth-error/page.tsx +26 -0
  59. package/dist/templates/app/(auth)/signup/page.tsx +24 -2
  60. package/dist/templates/app/api/v1/billing/cancel/route.ts +5 -8
  61. package/dist/templates/app/api/v1/billing/checkout/route.ts +3 -3
  62. package/dist/templates/app/api/v1/billing/portal/route.ts +2 -2
  63. package/dist/templates/app/api/v1/billing/webhooks/polar/route.ts +410 -0
  64. package/dist/templates/contents/themes/starter/config/app.config.ts +21 -0
  65. package/migrations/090_sample_data.sql +1 -1
  66. package/package.json +39 -2
  67. package/scripts/build/registry/generators/billing-registry.mjs +6 -3
  68. package/templates/app/(auth)/auth-error/page.tsx +26 -0
  69. package/templates/app/(auth)/signup/page.tsx +24 -2
  70. package/templates/app/api/v1/billing/cancel/route.ts +5 -8
  71. package/templates/app/api/v1/billing/checkout/route.ts +3 -3
  72. package/templates/app/api/v1/billing/portal/route.ts +2 -2
  73. package/templates/app/api/v1/billing/webhooks/polar/route.ts +410 -0
  74. package/templates/contents/themes/starter/config/app.config.ts +21 -0
  75. /package/dist/lib/billing/gateways/{stripe.d.js → interface.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"LoginForm.d.ts","sourceRoot":"","sources":["../../../../src/components/auth/forms/LoginForm.tsx"],"names":[],"mappings":"AAmGA,wBAAgB,SAAS,4CA0XxB"}
1
+ {"version":3,"file":"LoginForm.d.ts","sourceRoot":"","sources":["../../../../src/components/auth/forms/LoginForm.tsx"],"names":[],"mappings":"AAmGA,wBAAgB,SAAS,4CA4YxB"}
@@ -22,7 +22,7 @@ import { sel } from "../../../lib/test/index.js";
22
22
  import { useTranslations } from "next-intl";
23
23
  import { AuthTranslationPreloader } from "../../../lib/i18n/AuthTranslationPreloader.js";
24
24
  import { DevKeyring } from "../DevKeyring.js";
25
- import { DEV_CONFIG } from "../../../lib/config/config-sync.js";
25
+ import { DEV_CONFIG, PUBLIC_AUTH_CONFIG } from "../../../lib/config/config-sync.js";
26
26
  function getErrorMessageFromCode(error, t, context) {
27
27
  const authError = error;
28
28
  const errorCode = authError.code || getErrorCodeFromMessage(error.message);
@@ -81,11 +81,16 @@ const loginSchema = z.object({
81
81
  password: z.string().min(6, "Password must be at least 6 characters")
82
82
  });
83
83
  function LoginForm() {
84
- var _a;
84
+ var _a, _b, _c;
85
+ const registrationMode = PUBLIC_AUTH_CONFIG.registration.mode;
86
+ const googleEnabled = PUBLIC_AUTH_CONFIG.providers.google.enabled;
87
+ const signupVisible = registrationMode === "open";
88
+ const devKeyringActive = process.env.NODE_ENV !== "production" && !!((_b = (_a = DEV_CONFIG) == null ? void 0 : _a.devKeyring) == null ? void 0 : _b.enabled);
89
+ const emailLoginAllowed = registrationMode !== "domain-restricted" || devKeyringActive;
85
90
  const [loadingProvider, setLoadingProvider] = useState(null);
86
91
  const [error, setError] = useState(null);
87
92
  const [statusMessage, setStatusMessage] = useState("");
88
- const [showEmailForm, setShowEmailForm] = useState(false);
93
+ const [showEmailForm, setShowEmailForm] = useState(!googleEnabled);
89
94
  const isProcessingRef = useRef(false);
90
95
  const { signIn, googleSignIn } = useAuth();
91
96
  const { lastMethod, isReady } = useLastAuthMethod();
@@ -197,7 +202,7 @@ function LoginForm() {
197
202
  /* @__PURE__ */ jsx(Users, { className: "h-4 w-4" }),
198
203
  /* @__PURE__ */ jsx(AlertDescription, { children: t("login.inviteBanner") })
199
204
  ] }),
200
- isReady && lastMethod === "google" ? /* @__PURE__ */ jsx(LastUsedBadge, { text: t("login.form.lastUsed"), children: /* @__PURE__ */ jsxs(
205
+ googleEnabled && /* @__PURE__ */ jsx(Fragment, { children: isReady && lastMethod === "google" ? /* @__PURE__ */ jsx(LastUsedBadge, { text: t("login.form.lastUsed"), children: /* @__PURE__ */ jsxs(
201
206
  Button,
202
207
  {
203
208
  type: "button",
@@ -227,8 +232,8 @@ function LoginForm() {
227
232
  t("login.form.continueWithGoogle")
228
233
  ]
229
234
  }
230
- ),
231
- !showEmailForm && /* @__PURE__ */ jsx("div", { className: "text-center", children: isReady && lastMethod === "email" ? /* @__PURE__ */ jsx(LastUsedBadge, { text: t("login.form.lastUsed"), children: /* @__PURE__ */ jsx(
235
+ ) }),
236
+ !showEmailForm && googleEnabled && emailLoginAllowed && /* @__PURE__ */ jsx("div", { className: "text-center", children: isReady && lastMethod === "email" ? /* @__PURE__ */ jsx(LastUsedBadge, { text: t("login.form.lastUsed"), children: /* @__PURE__ */ jsx(
232
237
  "button",
233
238
  {
234
239
  type: "button",
@@ -249,7 +254,7 @@ function LoginForm() {
249
254
  children: t("login.form.loginWithEmail", { defaultValue: "Sign in with Email" })
250
255
  }
251
256
  ) }),
252
- showEmailForm && /* @__PURE__ */ jsxs(Fragment, { children: [
257
+ showEmailForm && emailLoginAllowed && /* @__PURE__ */ jsxs(Fragment, { children: [
253
258
  /* @__PURE__ */ jsxs("div", { className: "relative my-6", children: [
254
259
  /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx(Separator, { className: "w-full" }) }),
255
260
  /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs uppercase", children: /* @__PURE__ */ jsx("span", { className: "bg-background px-2 text-muted-foreground", children: t("login.form.orContinueWith") }) })
@@ -403,7 +408,7 @@ function LoginForm() {
403
408
  }
404
409
  ),
405
410
  /* @__PURE__ */ jsx("div", { id: "submit-help", className: "sr-only", children: t("login.form.submitHelp") }),
406
- /* @__PURE__ */ jsx("div", { className: "text-center mt-4", children: /* @__PURE__ */ jsx(
411
+ googleEnabled && /* @__PURE__ */ jsx("div", { className: "text-center mt-4", children: /* @__PURE__ */ jsx(
407
412
  "button",
408
413
  {
409
414
  type: "button",
@@ -418,7 +423,7 @@ function LoginForm() {
418
423
  )
419
424
  ] })
420
425
  ] }),
421
- /* @__PURE__ */ jsx(
426
+ signupVisible && /* @__PURE__ */ jsx(
422
427
  CardFooter,
423
428
  {
424
429
  "data-cy": sel("auth.login.footer"),
@@ -441,7 +446,7 @@ function LoginForm() {
441
446
  ]
442
447
  }
443
448
  ),
444
- ((_a = DEV_CONFIG) == null ? void 0 : _a.devKeyring) && /* @__PURE__ */ jsx(DevKeyring, { config: DEV_CONFIG.devKeyring })
449
+ ((_c = DEV_CONFIG) == null ? void 0 : _c.devKeyring) && /* @__PURE__ */ jsx(DevKeyring, { config: DEV_CONFIG.devKeyring })
445
450
  ] });
446
451
  }
447
452
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"SignupForm.d.ts","sourceRoot":"","sources":["../../../../src/components/auth/forms/SignupForm.tsx"],"names":[],"mappings":"AA4BA,wBAAgB,UAAU,4CA0fzB"}
1
+ {"version":3,"file":"SignupForm.d.ts","sourceRoot":"","sources":["../../../../src/components/auth/forms/SignupForm.tsx"],"names":[],"mappings":"AA6BA,wBAAgB,UAAU,4CA8fzB"}
@@ -19,6 +19,7 @@ import { signupSchema } from "../../../lib/validation.js";
19
19
  import { sel } from "../../../lib/test/index.js";
20
20
  import { useTranslations } from "next-intl";
21
21
  import { AuthTranslationPreloader } from "../../../lib/i18n/AuthTranslationPreloader.js";
22
+ import { PUBLIC_AUTH_CONFIG } from "../../../lib/config/config-sync.js";
22
23
  import { toast } from "sonner";
23
24
  function SignupForm() {
24
25
  const router = useRouter();
@@ -438,30 +439,32 @@ function SignupForm() {
438
439
  }
439
440
  )
440
441
  ] }),
441
- /* @__PURE__ */ jsxs("div", { className: "relative my-4", children: [
442
- /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx(Separator, { className: "w-full" }) }),
443
- /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs uppercase", children: /* @__PURE__ */ jsx("span", { className: "bg-background px-2 text-muted-foreground", children: "Or continue with" }) })
444
- ] }),
445
- /* @__PURE__ */ jsxs(
446
- Button,
447
- {
448
- type: "button",
449
- variant: "outline",
450
- onClick: handleGoogleSignUp,
451
- disabled: !!loadingProvider,
452
- className: "w-full",
453
- "data-cy": sel("auth.signup.googleButton"),
454
- children: [
455
- loadingProvider === "google" ? /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsxs("svg", { className: "mr-2 h-4 w-4", viewBox: "0 0 24 24", children: [
456
- /* @__PURE__ */ jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }),
457
- /* @__PURE__ */ jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }),
458
- /* @__PURE__ */ jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }),
459
- /* @__PURE__ */ jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" })
460
- ] }),
461
- "Continue with Google"
462
- ]
463
- }
464
- )
442
+ PUBLIC_AUTH_CONFIG.providers.google.enabled && /* @__PURE__ */ jsxs(Fragment, { children: [
443
+ /* @__PURE__ */ jsxs("div", { className: "relative my-4", children: [
444
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx(Separator, { className: "w-full" }) }),
445
+ /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs uppercase", children: /* @__PURE__ */ jsx("span", { className: "bg-background px-2 text-muted-foreground", children: "Or continue with" }) })
446
+ ] }),
447
+ /* @__PURE__ */ jsxs(
448
+ Button,
449
+ {
450
+ type: "button",
451
+ variant: "outline",
452
+ onClick: handleGoogleSignUp,
453
+ disabled: !!loadingProvider,
454
+ className: "w-full",
455
+ "data-cy": sel("auth.signup.googleButton"),
456
+ children: [
457
+ loadingProvider === "google" ? /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsxs("svg", { className: "mr-2 h-4 w-4", viewBox: "0 0 24 24", children: [
458
+ /* @__PURE__ */ jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }),
459
+ /* @__PURE__ */ jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }),
460
+ /* @__PURE__ */ jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }),
461
+ /* @__PURE__ */ jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" })
462
+ ] }),
463
+ "Continue with Google"
464
+ ]
465
+ }
466
+ )
467
+ ] })
465
468
  ] }),
466
469
  /* @__PURE__ */ jsx(
467
470
  CardFooter,
@@ -0,0 +1,2 @@
1
+ export declare function AuthErrorPage(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=AuthErrorPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthErrorPage.d.ts","sourceRoot":"","sources":["../../../../src/components/auth/pages/AuthErrorPage.tsx"],"names":[],"mappings":"AAOA,wBAAgB,aAAa,4CAiD5B"}
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useSearchParams } from "next/navigation";
4
+ import { useTranslations } from "next-intl";
5
+ import { ShieldAlert, ArrowLeft } from "lucide-react";
6
+ import { Button } from "../../ui/button.js";
7
+ function AuthErrorPage() {
8
+ const searchParams = useSearchParams();
9
+ const t = useTranslations("auth.error");
10
+ const error = searchParams.get("error");
11
+ const code = (error == null ? void 0 : error.toLowerCase()) ?? "";
12
+ const isAccountError = code === "unable_to_create_user" || code === "unable_to_create_session" || code === "user_not_found";
13
+ const titleKey = isAccountError ? "unable_to_create.title" : "generic.title";
14
+ const descriptionKey = isAccountError ? "unable_to_create.description" : "generic.description";
15
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6", "data-cy": "auth-error-page", children: [
16
+ /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx("div", { className: "rounded-full p-4 bg-destructive/10", children: /* @__PURE__ */ jsx(ShieldAlert, { className: "h-8 w-8 text-destructive", strokeWidth: 1.5 }) }) }),
17
+ /* @__PURE__ */ jsxs("div", { className: "text-center space-y-2", children: [
18
+ /* @__PURE__ */ jsx(
19
+ "h1",
20
+ {
21
+ className: "text-xl font-semibold text-foreground",
22
+ "data-cy": "auth-error-title",
23
+ children: t(titleKey)
24
+ }
25
+ ),
26
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground leading-relaxed", children: t(descriptionKey) })
27
+ ] }),
28
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 pt-2", children: /* @__PURE__ */ jsx(
29
+ Button,
30
+ {
31
+ asChild: true,
32
+ className: "w-full",
33
+ "data-cy": "auth-error-back-to-login",
34
+ children: /* @__PURE__ */ jsxs("a", { href: "/login", children: [
35
+ /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2 h-4 w-4" }),
36
+ t("backToLogin")
37
+ ] })
38
+ }
39
+ ) })
40
+ ] });
41
+ }
42
+ export {
43
+ AuthErrorPage
44
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Better Auth Plugin: Registration Guard
3
+ *
4
+ * This plugin intercepts OAuth signup attempts BEFORE user creation to enforce
5
+ * registration mode restrictions at the earliest possible point.
6
+ *
7
+ * Security layers:
8
+ * 1. This plugin (OAuth pre-validation)
9
+ * 2. API route handler (endpoint blocking)
10
+ * 3. Database hooks (final validation)
11
+ */
12
+ import type { BetterAuthPlugin } from 'better-auth';
13
+ export declare const registrationGuardPlugin: () => BetterAuthPlugin;
14
+ //# sourceMappingURL=registration-guard-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration-guard-plugin.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/registration-guard-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,eAAO,MAAM,uBAAuB,QAAO,gBA2C1C,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { AUTH_CONFIG } from "../config/index.js";
2
+ import { TeamService } from "../services/team.service.js";
3
+ const registrationGuardPlugin = () => {
4
+ return {
5
+ id: "registration-guard",
6
+ hooks: {
7
+ before: [
8
+ {
9
+ // Intercept social signup attempts
10
+ matcher: (ctx) => {
11
+ const path = ctx.path || "";
12
+ return path.includes("/sign-up/social") || path.includes("/callback/") || path.includes("/sign-up");
13
+ },
14
+ handler: async (ctx) => {
15
+ var _a, _b;
16
+ const registrationMode = ((_b = (_a = AUTH_CONFIG) == null ? void 0 : _a.registration) == null ? void 0 : _b.mode) ?? "open";
17
+ if (registrationMode === "invitation-only") {
18
+ const request = ctx.request;
19
+ const url = new URL(request.url);
20
+ const hasInviteToken = request.headers.get("x-invite-token") || url.searchParams.get("inviteToken");
21
+ if (!hasInviteToken) {
22
+ const teamExists = await TeamService.hasGlobal();
23
+ if (teamExists) {
24
+ throw new Error("SIGNUP_RESTRICTED: Registration requires an invitation. Use an invite link or contact an administrator.");
25
+ }
26
+ }
27
+ }
28
+ return ctx;
29
+ }
30
+ }
31
+ ]
32
+ }
33
+ };
34
+ };
35
+ export {
36
+ registrationGuardPlugin
37
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Registration Helper Functions
3
+ *
4
+ * Pure helper functions for registration mode logic.
5
+ * These functions have no side effects and can be used
6
+ * on both server and client (where appropriate).
7
+ */
8
+ import type { AuthConfig, RegistrationMode, PublicAuthConfig } from '../config/types';
9
+ /**
10
+ * Check if public registration (self-signup) is allowed.
11
+ *
12
+ * Only 'open' mode allows unrestricted public registration.
13
+ * 'domain-restricted' allows registration only via Google OAuth for allowed domains.
14
+ */
15
+ export declare function isRegistrationOpen(mode: RegistrationMode): boolean;
16
+ /**
17
+ * Check if an email domain is in the allowed domains list.
18
+ * Returns false if allowedDomains is empty — callers should handle
19
+ * the empty-list case separately (e.g., skip validation entirely).
20
+ *
21
+ * @param email - Full email address (e.g., "user@nextspark.dev")
22
+ * @param allowedDomains - List of allowed domains without @ (e.g., ["nextspark.dev"])
23
+ * @returns true if the email domain is allowed
24
+ */
25
+ export declare function isDomainAllowed(email: string, allowedDomains: string[]): boolean;
26
+ /**
27
+ * Check if Google OAuth should be enabled based on auth config.
28
+ *
29
+ * Google is disabled when:
30
+ * - providers.google.enabled is explicitly false
31
+ * - GOOGLE_CLIENT_ID env var is not set (runtime check, not done here)
32
+ */
33
+ export declare function isGoogleAuthEnabled(authConfig: AuthConfig): boolean;
34
+ /**
35
+ * Check if the signup page should be accessible.
36
+ *
37
+ * Signup page is hidden for:
38
+ * - 'domain-restricted': Registration happens via Google OAuth on login page
39
+ * - 'invitation-only': Only accessible with valid invite params
40
+ */
41
+ export declare function isSignupPageVisible(mode: RegistrationMode): boolean;
42
+ /**
43
+ * Check if email+password signup form should be shown.
44
+ */
45
+ export declare function isEmailSignupEnabled(mode: RegistrationMode): boolean;
46
+ /**
47
+ * Check if signup should be blocked entirely (server-side enforcement).
48
+ *
49
+ * In 'domain-restricted' mode, email+password signup is blocked
50
+ * but Google OAuth may be allowed (with domain check).
51
+ */
52
+ export declare function shouldBlockSignup(mode: RegistrationMode, isOAuth: boolean): boolean;
53
+ /**
54
+ * Check if email+password login should be visible on the login page.
55
+ *
56
+ * In 'domain-restricted' mode, only Google OAuth is shown — email login is hidden
57
+ * because new users cannot register via email and the UX is simplified to Google-only.
58
+ */
59
+ export declare function isEmailLoginVisible(mode: RegistrationMode): boolean;
60
+ /**
61
+ * Build a PublicAuthConfig from the full AuthConfig.
62
+ * Strips sensitive data (allowedDomains) for client exposure.
63
+ */
64
+ export declare function getPublicAuthConfig(authConfig: AuthConfig): PublicAuthConfig;
65
+ //# sourceMappingURL=registration-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/auth/registration-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAErF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAShF;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAEnE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,OAAO,GACf,OAAO,CAGT;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAEnE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAW5E"}
@@ -0,0 +1,51 @@
1
+ function isRegistrationOpen(mode) {
2
+ return mode === "open";
3
+ }
4
+ function isDomainAllowed(email, allowedDomains) {
5
+ var _a;
6
+ if (!allowedDomains.length) return false;
7
+ const domain = (_a = email.split("@")[1]) == null ? void 0 : _a.toLowerCase();
8
+ if (!domain) return false;
9
+ return allowedDomains.some(
10
+ (allowed) => domain === allowed.toLowerCase()
11
+ );
12
+ }
13
+ function isGoogleAuthEnabled(authConfig) {
14
+ var _a, _b;
15
+ return ((_b = (_a = authConfig.providers) == null ? void 0 : _a.google) == null ? void 0 : _b.enabled) !== false;
16
+ }
17
+ function isSignupPageVisible(mode) {
18
+ return mode === "open";
19
+ }
20
+ function isEmailSignupEnabled(mode) {
21
+ return mode === "open";
22
+ }
23
+ function shouldBlockSignup(mode, isOAuth) {
24
+ if (mode === "domain-restricted" && !isOAuth) return true;
25
+ return false;
26
+ }
27
+ function isEmailLoginVisible(mode) {
28
+ return mode !== "domain-restricted";
29
+ }
30
+ function getPublicAuthConfig(authConfig) {
31
+ return {
32
+ registration: {
33
+ mode: authConfig.registration.mode
34
+ },
35
+ providers: {
36
+ google: {
37
+ enabled: isGoogleAuthEnabled(authConfig)
38
+ }
39
+ }
40
+ };
41
+ }
42
+ export {
43
+ getPublicAuthConfig,
44
+ isDomainAllowed,
45
+ isEmailLoginVisible,
46
+ isEmailSignupEnabled,
47
+ isGoogleAuthEnabled,
48
+ isRegistrationOpen,
49
+ isSignupPageVisible,
50
+ shouldBlockSignup
51
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AA+C1G,eAAO,MAAM,IAAI;;;;kGAiSy1zgB,CAAC;oBAAyB,CAAC;;sBAAqD,CAAC;;qBAA4D,CAAC;;sBAA2E,CAAC;;uBAAgE,CAAC;;uBAAoD,CAAC;;0BAA2D,CAAC;6BAAwC,CAAC;mBAA8B,CAAC;oBAAgD,CAAC;;0BAAsD,CAAC;6BAAuD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kGAA8pD,CAAC;oBAAyB,CAAC;;sBAAqD,CAAC;;qBAA4D,CAAC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAjD1hlqB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;AACjD,MAAM,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,kBAAkB,EAAE,QAAQ,EAAE,CAAC;CAC/C,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAO9B"}
package/dist/lib/auth.js CHANGED
@@ -3,10 +3,12 @@ import { Pool } from "pg";
3
3
  import { nextCookies } from "better-auth/next-js";
4
4
  import { parseSSLConfig, stripSSLParams } from "./db.js";
5
5
  import { EmailFactory, emailTemplates } from "./email/index.js";
6
- import { I18N_CONFIG, USER_ROLES_CONFIG, TEAMS_CONFIG, APP_CONFIG_MERGED } from "./config/index.js";
6
+ import { I18N_CONFIG, USER_ROLES_CONFIG, TEAMS_CONFIG, AUTH_CONFIG, APP_CONFIG_MERGED } from "./config/index.js";
7
7
  import { getUserFlags } from "./services/user-flags.service.js";
8
8
  import { TeamService } from "./services/team.service.js";
9
9
  import { shouldSkipTeamCreation } from "./auth-context.js";
10
+ import { isDomainAllowed } from "./auth/registration-helpers.js";
11
+ import { registrationGuardPlugin } from "./auth/registration-guard-plugin.js";
10
12
  import { getCorsOrigins } from "./utils/cors.js";
11
13
  const isProd = process.env.NODE_ENV === "production";
12
14
  const baseUrl = process.env.BETTER_AUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:5173";
@@ -141,7 +143,13 @@ const auth = betterAuth({
141
143
  baseURL: baseUrl,
142
144
  // Use unified CORS configuration from app.config.ts + theme extensions + env vars
143
145
  trustedOrigins: getCorsOrigins(APP_CONFIG_MERGED),
146
+ // Redirect auth errors to our custom error page instead of Better Auth's default
147
+ onAPIError: {
148
+ errorURL: "/auth-error"
149
+ },
144
150
  plugins: [
151
+ registrationGuardPlugin(),
152
+ // Intercept OAuth signup attempts
145
153
  nextCookies()
146
154
  // MUST be the last plugin for Next.js cookie handling
147
155
  ],
@@ -160,6 +168,27 @@ const auth = betterAuth({
160
168
  databaseHooks: {
161
169
  user: {
162
170
  create: {
171
+ // Validate registration mode before creating user
172
+ before: async (user) => {
173
+ var _a, _b, _c, _d;
174
+ const registrationMode = ((_b = (_a = AUTH_CONFIG) == null ? void 0 : _a.registration) == null ? void 0 : _b.mode) ?? "open";
175
+ if (registrationMode === "invitation-only") {
176
+ if (!shouldSkipTeamCreation()) {
177
+ const existingTeam = await TeamService.getGlobal();
178
+ if (existingTeam) {
179
+ throw new Error("SIGNUP_RESTRICTED: Registration requires an invitation. Contact an administrator.");
180
+ }
181
+ }
182
+ }
183
+ if (registrationMode === "domain-restricted") {
184
+ const allowedDomains = ((_d = (_c = AUTH_CONFIG) == null ? void 0 : _c.registration) == null ? void 0 : _d.allowedDomains) ?? [];
185
+ if (allowedDomains.length > 0 && !isDomainAllowed(user.email, allowedDomains)) {
186
+ console.log(`[Auth] Blocked registration for ${user.email}: domain not in allowedDomains (allowed: ${allowedDomains.join(", ")})`);
187
+ throw new Error(`DOMAIN_NOT_ALLOWED: Email domain not authorized. Please use an email from: ${allowedDomains.join(", ")}`);
188
+ }
189
+ }
190
+ return user;
191
+ },
163
192
  // Create team when a new user signs up (email/password or OAuth)
164
193
  // Team type depends on configured teams mode
165
194
  after: async (user) => {
@@ -193,6 +222,30 @@ const auth = betterAuth({
193
222
  }
194
223
  }
195
224
  }
225
+ },
226
+ session: {
227
+ create: {
228
+ // Enforce domain restrictions on EVERY login (not just signup)
229
+ before: async (session) => {
230
+ var _a, _b, _c, _d, _e;
231
+ const registrationMode = ((_b = (_a = AUTH_CONFIG) == null ? void 0 : _a.registration) == null ? void 0 : _b.mode) ?? "open";
232
+ if (registrationMode === "domain-restricted") {
233
+ const allowedDomains = ((_d = (_c = AUTH_CONFIG) == null ? void 0 : _c.registration) == null ? void 0 : _d.allowedDomains) ?? [];
234
+ if (allowedDomains.length > 0) {
235
+ const result = await pool.query(
236
+ "SELECT email FROM users WHERE id = $1 LIMIT 1",
237
+ [session.userId]
238
+ );
239
+ const email = (_e = result.rows[0]) == null ? void 0 : _e.email;
240
+ if (email && !isDomainAllowed(email, allowedDomains)) {
241
+ console.log(`[Auth] Blocked sign-in for ${email}: domain not in allowedDomains`);
242
+ return false;
243
+ }
244
+ }
245
+ }
246
+ return session;
247
+ }
248
+ }
196
249
  }
197
250
  },
198
251
  callbacks: {
@@ -40,6 +40,11 @@ export interface PlanDefinition {
40
40
  /** Stripe price IDs (P2: Stripe Integration) */
41
41
  stripePriceIdMonthly?: string | null;
42
42
  stripePriceIdYearly?: string | null;
43
+ /** Generic price IDs for any payment provider (checked first, falls back to stripe-specific) */
44
+ providerPriceIds?: {
45
+ monthly?: string | null;
46
+ yearly?: string | null;
47
+ };
43
48
  }
44
49
  export interface ActionMappings {
45
50
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../../../src/lib/billing/config-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;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25 @@
1
+ /**
2
+ * Billing Gateway Factory
3
+ *
4
+ * Returns the configured BillingGateway implementation based on the
5
+ * provider setting in the billing registry. Uses lazy loading so that
6
+ * provider SDKs (Stripe, Polar, etc.) are only imported when needed.
7
+ *
8
+ * Usage:
9
+ * import { getBillingGateway } from '@nextsparkjs/core/lib/billing/gateways/factory'
10
+ * const session = await getBillingGateway().createCheckoutSession(params)
11
+ */
12
+ import type { BillingGateway } from './interface';
13
+ /**
14
+ * Get the billing gateway for the configured payment provider.
15
+ * Singleton - the same instance is returned on subsequent calls.
16
+ *
17
+ * Provider is determined by BILLING_REGISTRY.config.provider (from billing.config.ts).
18
+ */
19
+ export declare function getBillingGateway(): BillingGateway;
20
+ /**
21
+ * Reset the cached gateway instance.
22
+ * Useful for testing or when billing config changes at runtime.
23
+ */
24
+ export declare function resetBillingGateway(): void;
25
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/lib/billing/gateways/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CA4BlD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
@@ -0,0 +1,34 @@
1
+ import { BILLING_REGISTRY } from "@nextsparkjs/registries/billing-registry";
2
+ let gatewayInstance = null;
3
+ function getBillingGateway() {
4
+ if (!gatewayInstance) {
5
+ const provider = BILLING_REGISTRY.provider;
6
+ switch (provider) {
7
+ case "stripe": {
8
+ const { StripeGateway } = require("./stripe");
9
+ gatewayInstance = new StripeGateway();
10
+ break;
11
+ }
12
+ case "polar": {
13
+ const { PolarGateway } = require("./polar");
14
+ gatewayInstance = new PolarGateway();
15
+ break;
16
+ }
17
+ // Future providers:
18
+ // case 'paddle': { ... }
19
+ // case 'lemonsqueezy': { ... }
20
+ default:
21
+ throw new Error(
22
+ `Unsupported billing provider: "${provider}". Supported providers: stripe, polar. Check your billing.config.ts provider setting.`
23
+ );
24
+ }
25
+ }
26
+ return gatewayInstance;
27
+ }
28
+ function resetBillingGateway() {
29
+ gatewayInstance = null;
30
+ }
31
+ export {
32
+ getBillingGateway,
33
+ resetBillingGateway
34
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Billing Gateway Interface
3
+ *
4
+ * Defines the contract that all payment provider implementations must satisfy.
5
+ * Consumers interact with this interface via the factory (getBillingGateway()),
6
+ * making provider switching a configuration change rather than a code change.
7
+ */
8
+ import type { CheckoutSessionResult, PortalSessionResult, SubscriptionResult, CustomerResult, WebhookEventResult, CreateCheckoutParams, CreatePortalParams, CreateCustomerParams, UpdateSubscriptionParams } from './types';
9
+ export interface BillingGateway {
10
+ createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult>;
11
+ createPortalSession(params: CreatePortalParams): Promise<PortalSessionResult>;
12
+ getCustomer(customerId: string): Promise<CustomerResult>;
13
+ createCustomer(params: CreateCustomerParams): Promise<CustomerResult>;
14
+ updateSubscriptionPlan(params: UpdateSubscriptionParams): Promise<SubscriptionResult>;
15
+ cancelSubscriptionAtPeriodEnd(subscriptionId: string): Promise<SubscriptionResult>;
16
+ cancelSubscriptionImmediately(subscriptionId: string): Promise<SubscriptionResult>;
17
+ reactivateSubscription(subscriptionId: string): Promise<SubscriptionResult>;
18
+ verifyWebhookSignature(payload: string | Buffer, signatureOrHeaders: string | Record<string, string>): WebhookEventResult;
19
+ }
20
+ //# sourceMappingURL=interface.d.ts.map