@robelest/convex-auth 0.0.2 → 0.0.3-preview.1

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 (173) hide show
  1. package/dist/bin.cjs +1 -1
  2. package/dist/client/index.d.ts +33 -9
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +79 -13
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/component/_generated/component.d.ts +48 -0
  7. package/dist/component/_generated/component.d.ts.map +1 -1
  8. package/dist/component/index.d.ts +10 -4
  9. package/dist/component/index.d.ts.map +1 -1
  10. package/dist/component/index.js +8 -3
  11. package/dist/component/index.js.map +1 -1
  12. package/dist/component/public.d.ts +163 -3
  13. package/dist/component/public.d.ts.map +1 -1
  14. package/dist/component/public.js +124 -0
  15. package/dist/component/public.js.map +1 -1
  16. package/dist/component/schema.d.ts +81 -2
  17. package/dist/component/schema.d.ts.map +1 -1
  18. package/dist/component/schema.js +45 -0
  19. package/dist/component/schema.js.map +1 -1
  20. package/dist/providers/anonymous.d.ts +3 -0
  21. package/dist/providers/anonymous.d.ts.map +1 -1
  22. package/dist/providers/anonymous.js +3 -0
  23. package/dist/providers/anonymous.js.map +1 -1
  24. package/dist/providers/credentials.d.ts +3 -0
  25. package/dist/providers/credentials.d.ts.map +1 -1
  26. package/dist/providers/credentials.js +3 -0
  27. package/dist/providers/credentials.js.map +1 -1
  28. package/dist/providers/email.d.ts +3 -0
  29. package/dist/providers/email.d.ts.map +1 -1
  30. package/dist/providers/email.js +3 -0
  31. package/dist/providers/email.js.map +1 -1
  32. package/dist/providers/passkey.d.ts +7 -1
  33. package/dist/providers/passkey.d.ts.map +1 -1
  34. package/dist/providers/passkey.js +7 -1
  35. package/dist/providers/passkey.js.map +1 -1
  36. package/dist/providers/password.d.ts +3 -0
  37. package/dist/providers/password.d.ts.map +1 -1
  38. package/dist/providers/password.js +3 -0
  39. package/dist/providers/password.js.map +1 -1
  40. package/dist/providers/phone.d.ts +3 -0
  41. package/dist/providers/phone.d.ts.map +1 -1
  42. package/dist/providers/phone.js +3 -0
  43. package/dist/providers/phone.js.map +1 -1
  44. package/dist/providers/totp.d.ts +8 -0
  45. package/dist/providers/totp.d.ts.map +1 -1
  46. package/dist/providers/totp.js +8 -0
  47. package/dist/providers/totp.js.map +1 -1
  48. package/dist/server/convex-auth.d.ts +185 -25
  49. package/dist/server/convex-auth.d.ts.map +1 -1
  50. package/dist/server/convex-auth.js +317 -58
  51. package/dist/server/convex-auth.js.map +1 -1
  52. package/dist/server/email-templates.d.ts +18 -0
  53. package/dist/server/email-templates.d.ts.map +1 -0
  54. package/dist/server/email-templates.js +74 -0
  55. package/dist/server/email-templates.js.map +1 -0
  56. package/dist/server/errors.d.ts +146 -0
  57. package/dist/server/errors.d.ts.map +1 -0
  58. package/dist/server/errors.js +176 -0
  59. package/dist/server/errors.js.map +1 -0
  60. package/dist/server/implementation/apiKey.d.ts +74 -0
  61. package/dist/server/implementation/apiKey.d.ts.map +1 -0
  62. package/dist/server/implementation/apiKey.js +139 -0
  63. package/dist/server/implementation/apiKey.js.map +1 -0
  64. package/dist/server/implementation/index.d.ts +151 -14
  65. package/dist/server/implementation/index.d.ts.map +1 -1
  66. package/dist/server/implementation/index.js +216 -24
  67. package/dist/server/implementation/index.js.map +1 -1
  68. package/dist/server/implementation/mutations/createAccountFromCredentials.d.ts.map +1 -1
  69. package/dist/server/implementation/mutations/createAccountFromCredentials.js +2 -1
  70. package/dist/server/implementation/mutations/createAccountFromCredentials.js.map +1 -1
  71. package/dist/server/implementation/mutations/createVerificationCode.d.ts +2 -2
  72. package/dist/server/implementation/mutations/index.d.ts +6 -6
  73. package/dist/server/implementation/mutations/modifyAccount.d.ts.map +1 -1
  74. package/dist/server/implementation/mutations/modifyAccount.js +2 -1
  75. package/dist/server/implementation/mutations/modifyAccount.js.map +1 -1
  76. package/dist/server/implementation/mutations/userOAuth.d.ts.map +1 -1
  77. package/dist/server/implementation/mutations/userOAuth.js +2 -1
  78. package/dist/server/implementation/mutations/userOAuth.js.map +1 -1
  79. package/dist/server/implementation/mutations/verifierSignature.d.ts.map +1 -1
  80. package/dist/server/implementation/mutations/verifierSignature.js +2 -1
  81. package/dist/server/implementation/mutations/verifierSignature.js.map +1 -1
  82. package/dist/server/implementation/passkey.d.ts.map +1 -1
  83. package/dist/server/implementation/passkey.js +28 -29
  84. package/dist/server/implementation/passkey.js.map +1 -1
  85. package/dist/server/implementation/provider.d.ts.map +1 -1
  86. package/dist/server/implementation/provider.js +5 -4
  87. package/dist/server/implementation/provider.js.map +1 -1
  88. package/dist/server/implementation/redirects.d.ts.map +1 -1
  89. package/dist/server/implementation/redirects.js +2 -1
  90. package/dist/server/implementation/redirects.js.map +1 -1
  91. package/dist/server/implementation/refreshTokens.d.ts.map +1 -1
  92. package/dist/server/implementation/refreshTokens.js +2 -1
  93. package/dist/server/implementation/refreshTokens.js.map +1 -1
  94. package/dist/server/implementation/signIn.d.ts.map +1 -1
  95. package/dist/server/implementation/signIn.js +8 -18
  96. package/dist/server/implementation/signIn.js.map +1 -1
  97. package/dist/server/implementation/totp.d.ts.map +1 -1
  98. package/dist/server/implementation/totp.js +16 -17
  99. package/dist/server/implementation/totp.js.map +1 -1
  100. package/dist/server/implementation/users.d.ts.map +1 -1
  101. package/dist/server/implementation/users.js +3 -2
  102. package/dist/server/implementation/users.js.map +1 -1
  103. package/dist/server/index.d.ts +157 -3
  104. package/dist/server/index.d.ts.map +1 -1
  105. package/dist/server/index.js +180 -17
  106. package/dist/server/index.js.map +1 -1
  107. package/dist/server/oauth/authorizationUrl.d.ts.map +1 -1
  108. package/dist/server/oauth/authorizationUrl.js +2 -1
  109. package/dist/server/oauth/authorizationUrl.js.map +1 -1
  110. package/dist/server/oauth/callback.d.ts.map +1 -1
  111. package/dist/server/oauth/callback.js +5 -4
  112. package/dist/server/oauth/callback.js.map +1 -1
  113. package/dist/server/oauth/checks.d.ts.map +1 -1
  114. package/dist/server/oauth/checks.js +2 -1
  115. package/dist/server/oauth/checks.js.map +1 -1
  116. package/dist/server/oauth/convexAuth.d.ts.map +1 -1
  117. package/dist/server/oauth/convexAuth.js +3 -2
  118. package/dist/server/oauth/convexAuth.js.map +1 -1
  119. package/dist/server/provider_utils.d.ts +2 -0
  120. package/dist/server/provider_utils.d.ts.map +1 -1
  121. package/dist/server/types.d.ts +240 -5
  122. package/dist/server/types.d.ts.map +1 -1
  123. package/dist/server/utils.d.ts.map +1 -1
  124. package/dist/server/utils.js +2 -1
  125. package/dist/server/utils.js.map +1 -1
  126. package/dist/server/version.d.ts +2 -0
  127. package/dist/server/version.d.ts.map +1 -0
  128. package/dist/server/version.js +3 -0
  129. package/dist/server/version.js.map +1 -0
  130. package/package.json +7 -2
  131. package/src/cli/index.ts +1 -1
  132. package/src/cli/utils.ts +248 -0
  133. package/src/client/index.ts +105 -15
  134. package/src/component/_generated/component.ts +61 -0
  135. package/src/component/index.ts +11 -2
  136. package/src/component/public.ts +142 -0
  137. package/src/component/schema.ts +52 -0
  138. package/src/providers/anonymous.ts +3 -0
  139. package/src/providers/credentials.ts +3 -0
  140. package/src/providers/email.ts +3 -0
  141. package/src/providers/passkey.ts +8 -1
  142. package/src/providers/password.ts +3 -0
  143. package/src/providers/phone.ts +3 -0
  144. package/src/providers/totp.ts +9 -0
  145. package/src/server/convex-auth.ts +385 -73
  146. package/src/server/email-templates.ts +77 -0
  147. package/src/server/errors.ts +269 -0
  148. package/src/server/implementation/apiKey.ts +186 -0
  149. package/src/server/implementation/index.ts +288 -28
  150. package/src/server/implementation/mutations/createAccountFromCredentials.ts +2 -1
  151. package/src/server/implementation/mutations/modifyAccount.ts +2 -3
  152. package/src/server/implementation/mutations/userOAuth.ts +2 -1
  153. package/src/server/implementation/mutations/verifierSignature.ts +2 -1
  154. package/src/server/implementation/passkey.ts +33 -35
  155. package/src/server/implementation/provider.ts +5 -8
  156. package/src/server/implementation/redirects.ts +2 -3
  157. package/src/server/implementation/refreshTokens.ts +2 -1
  158. package/src/server/implementation/signIn.ts +9 -18
  159. package/src/server/implementation/totp.ts +18 -21
  160. package/src/server/implementation/users.ts +4 -7
  161. package/src/server/index.ts +240 -37
  162. package/src/server/oauth/authorizationUrl.ts +2 -1
  163. package/src/server/oauth/callback.ts +5 -4
  164. package/src/server/oauth/checks.ts +3 -1
  165. package/src/server/oauth/convexAuth.ts +6 -3
  166. package/src/server/types.ts +254 -5
  167. package/src/server/utils.ts +3 -1
  168. package/src/server/version.ts +2 -0
  169. package/dist/server/portal.d.ts +0 -116
  170. package/dist/server/portal.d.ts.map +0 -1
  171. package/dist/server/portal.js +0 -294
  172. package/dist/server/portal.js.map +0 -1
  173. package/src/server/portal.ts +0 -375
@@ -5,7 +5,7 @@ import {
5
5
  OAuth2Config,
6
6
  OIDCConfig,
7
7
  } from "@auth/core/providers";
8
- import { Theme } from "@auth/core/types";
8
+ import { Awaitable, Theme } from "@auth/core/types";
9
9
  import {
10
10
  AnyDataModel,
11
11
  FunctionReference,
@@ -82,6 +82,67 @@ export type ConvexAuthConfig = {
82
82
  */
83
83
  maxFailedAttempsPerHour?: number;
84
84
  };
85
+ /**
86
+ * API key configuration for programmatic access.
87
+ *
88
+ * Enables `auth.key.*` helpers for creating, verifying, and managing
89
+ * API keys with scoped permissions and optional per-key rate limiting.
90
+ */
91
+ apiKeys?: ApiKeyConfig;
92
+ /**
93
+ * Email transport configuration.
94
+ *
95
+ * Required for magic link authentication and the admin portal.
96
+ * The library generates email content (subject, styled HTML); you
97
+ * provide the delivery mechanism — Resend, SendGrid, SES, Postmark,
98
+ * or any other provider.
99
+ *
100
+ * When configured, a magic link email provider (`id: "email"`) is
101
+ * auto-registered — no need to add a separate Auth.js email provider
102
+ * to `providers`.
103
+ *
104
+ * Works seamlessly with the `@convex-dev/resend` Convex component:
105
+ *
106
+ * ```ts
107
+ * import { Resend } from "@convex-dev/resend";
108
+ *
109
+ * const resend = new Resend(components.resend, { testMode: false });
110
+ *
111
+ * const auth = new Auth(components.auth, {
112
+ * providers: [google],
113
+ * email: {
114
+ * from: "My App <noreply@example.com>",
115
+ * send: (ctx, params) => resend.sendEmail(ctx, params),
116
+ * },
117
+ * });
118
+ * ```
119
+ *
120
+ * Or with any email API directly:
121
+ *
122
+ * ```ts
123
+ * email: {
124
+ * from: "My App <noreply@example.com>",
125
+ * send: async (_ctx, { from, to, subject, html }) => {
126
+ * await fetch("https://api.resend.com/emails", {
127
+ * method: "POST",
128
+ * headers: {
129
+ * Authorization: `Bearer ${process.env.AUTH_RESEND_KEY}`,
130
+ * "Content-Type": "application/json",
131
+ * },
132
+ * body: JSON.stringify({ from, to, subject, html }),
133
+ * });
134
+ * },
135
+ * },
136
+ * ```
137
+ */
138
+ email?: EmailTransport;
139
+ /**
140
+ * Lifecycle callbacks for customizing sign-in behavior.
141
+ *
142
+ * Use `redirect` to control post-OAuth redirect URLs, and
143
+ * `createOrUpdateUser` or `afterUserCreatedOrUpdated` to
144
+ * customize account linking and user document creation.
145
+ */
85
146
  callbacks?: {
86
147
  /**
87
148
  * Control which URLs are allowed as a destination after OAuth sign-in
@@ -233,9 +294,11 @@ export type ConvexAuthConfig = {
233
294
  };
234
295
 
235
296
  /**
236
- * Same as Auth.js provider configs, but adds phone provider
237
- * for verification via SMS or another phone-number-connected messaging
238
- * service.
297
+ * Union of all supported auth provider config types.
298
+ *
299
+ * Includes Auth.js OAuth/OIDC providers, plus library-native providers:
300
+ * credentials, email, phone, passkey (WebAuthn), and TOTP (2FA).
301
+ * Each can be passed as a config object or a factory function.
239
302
  */
240
303
  export type AuthProviderConfig =
241
304
  | Exclude<
@@ -258,11 +321,30 @@ export type AuthProviderConfig =
258
321
  export interface EmailConfig<
259
322
  DataModel extends GenericDataModel = GenericDataModel,
260
323
  > extends AuthjsEmailConfig {
324
+ /**
325
+ * Send the verification token to the user.
326
+ *
327
+ * Overrides the Auth.js 1-arg signature to accept an optional
328
+ * Convex action context as the second argument. Library-native
329
+ * email providers use `ctx` to call `email.send(ctx, params)`.
330
+ */
331
+ sendVerificationRequest: (
332
+ params: {
333
+ identifier: string;
334
+ url: string;
335
+ expires: Date;
336
+ provider: AuthjsEmailConfig;
337
+ token: string;
338
+ theme: Theme;
339
+ request: Request;
340
+ },
341
+ ctx?: GenericActionCtx<AnyDataModel>,
342
+ ) => Awaitable<void>;
261
343
  /**
262
344
  * Before the token is verified, check other
263
345
  * provided parameters.
264
346
  *
265
- * Used to make sure tha OTPs are accompanied
347
+ * Used to make sure that OTPs are accompanied
266
348
  * with the correct email address.
267
349
  */
268
350
  authorize?: (
@@ -402,11 +484,15 @@ export interface TotpProviderConfig {
402
484
  };
403
485
  }
404
486
 
487
+ /** Credentials identifying a provider account (e.g. email + hashed password). */
405
488
  export type AuthAccountCredentials = {
489
+ /** Provider-specific account identifier (e.g. email address). */
406
490
  id: string;
491
+ /** Optional secret (e.g. hashed password). */
407
492
  secret?: string;
408
493
  };
409
494
 
495
+ /** Arguments for `auth.account.create()`. */
410
496
  export type AuthCreateAccountArgs = {
411
497
  provider: string;
412
498
  account: AuthAccountCredentials;
@@ -420,11 +506,13 @@ export type AuthCreateAccountArgs = {
420
506
  shouldLinkViaPhone?: boolean;
421
507
  };
422
508
 
509
+ /** Arguments for `auth.account.get()`. */
423
510
  export type AuthRetrieveAccountArgs = {
424
511
  provider: string;
425
512
  account: AuthAccountCredentials;
426
513
  };
427
514
 
515
+ /** Arguments for `auth.account.updateCredentials()`. */
428
516
  export type AuthUpdateAccountCredentialsArgs = {
429
517
  provider: string;
430
518
  account: {
@@ -433,21 +521,25 @@ export type AuthUpdateAccountCredentialsArgs = {
433
521
  };
434
522
  };
435
523
 
524
+ /** Arguments for `auth.session.invalidate()`. */
436
525
  export type AuthInvalidateSessionsArgs = {
437
526
  userId: GenericId<"user">;
438
527
  except?: GenericId<"session">[];
439
528
  };
440
529
 
530
+ /** Arguments for `auth.provider.signIn()`. */
441
531
  export type AuthProviderSignInArgs = {
442
532
  accountId?: GenericId<"account">;
443
533
  params?: Record<string, Value | undefined>;
444
534
  };
445
535
 
536
+ /** Return type of `auth.provider.signIn()` — user and session IDs, or `null` on failure. */
446
537
  export type AuthProviderSignInResult = {
447
538
  userId: GenericId<"user">;
448
539
  sessionId: GenericId<"session">;
449
540
  } | null;
450
541
 
542
+ /** Server-side auth helpers available on enriched action contexts. */
451
543
  export type AuthServerHelpers = {
452
544
  account: {
453
545
  create: (
@@ -524,8 +616,158 @@ export type AuthProviderMaterializedConfig =
524
616
  | PasskeyProviderConfig
525
617
  | TotpProviderConfig;
526
618
 
619
+ // ============================================================================
620
+ // Email transport types
621
+ // ============================================================================
622
+
623
+ /**
624
+ * Email delivery parameters passed to `EmailTransport.send`.
625
+ */
626
+ export interface EmailMessage {
627
+ /** Sender address (from `email.from` in your Auth config). */
628
+ from: string;
629
+ /** Recipient email address. */
630
+ to: string;
631
+ /** Email subject line. */
632
+ subject: string;
633
+ /** HTML body content. */
634
+ html: string;
635
+ }
636
+
637
+ /**
638
+ * Email transport configuration for the Auth library.
639
+ *
640
+ * Provides a delivery mechanism for library-generated emails
641
+ * (magic links, portal admin sign-in). The library owns the
642
+ * email content; you provide the transport.
643
+ */
644
+ export interface EmailTransport {
645
+ /** Sender address shown in the From field (e.g. "My App \<noreply@example.com\>"). */
646
+ from: string;
647
+ /**
648
+ * Deliver an email. Called by the library for magic links and portal emails.
649
+ *
650
+ * Receives the Convex action context as the first argument, enabling
651
+ * use with Convex components like `@convex-dev/resend`:
652
+ *
653
+ * ```ts
654
+ * send: (ctx, params) => resend.sendEmail(ctx, params)
655
+ * ```
656
+ *
657
+ * For plain HTTP email APIs, ignore the `ctx` parameter:
658
+ *
659
+ * ```ts
660
+ * send: async (_ctx, { from, to, subject, html }) => {
661
+ * await fetch("https://api.resend.com/emails", { ... });
662
+ * }
663
+ * ```
664
+ */
665
+ send: (
666
+ ctx: GenericActionCtx<any>,
667
+ params: EmailMessage,
668
+ ) => Promise<void>;
669
+ }
670
+
671
+ // ============================================================================
672
+ // API Key types
673
+ // ============================================================================
674
+
675
+ /**
676
+ * A single scope entry stored per API key.
677
+ * Uses a resource:action pattern for structured permissions.
678
+ *
679
+ * ```ts
680
+ * { resource: "users", actions: ["read", "list"] }
681
+ * ```
682
+ */
683
+ export interface KeyScope {
684
+ resource: string;
685
+ actions: string[];
686
+ }
687
+
688
+ /**
689
+ * Result of scope verification. Provides a `.can()` helper
690
+ * for checking if a key has a specific permission.
691
+ *
692
+ * ```ts
693
+ * const result = await auth.key.verify(ctx, rawKey);
694
+ * if (result.scopes.can("users", "read")) {
695
+ * // authorized
696
+ * }
697
+ * ```
698
+ */
699
+ export interface ScopeChecker {
700
+ /** Check if the key has permission for a given resource:action. */
701
+ can(resource: string, action: string): boolean;
702
+ /** The raw scope entries from the key. */
703
+ scopes: KeyScope[];
704
+ }
705
+
706
+ /**
707
+ * Configuration for API key support on the Auth class.
708
+ *
709
+ * ```ts
710
+ * const auth = new Auth(components.auth, {
711
+ * providers: [github],
712
+ * apiKeys: {
713
+ * scopes: {
714
+ * users: ["read", "list", "create", "delete"],
715
+ * messages: ["read", "write"],
716
+ * },
717
+ * defaultRateLimit: { maxRequests: 1000, windowMs: 3600000 },
718
+ * },
719
+ * });
720
+ * ```
721
+ */
722
+ export interface ApiKeyConfig {
723
+ /**
724
+ * Define the available resource:action scopes for your API keys.
725
+ * Keys can only be created with scopes that are a subset of these.
726
+ */
727
+ scopes?: Record<string, string[]>;
728
+ /**
729
+ * Default rate limit applied to new keys when not specified per-key.
730
+ * Uses a token-bucket algorithm.
731
+ */
732
+ defaultRateLimit?: { maxRequests: number; windowMs: number };
733
+ /**
734
+ * Key prefix. Defaults to `"sk_live_"`.
735
+ */
736
+ prefix?: string;
737
+ }
738
+
739
+ /**
740
+ * An API key record as returned by `auth.key.list()` and `auth.key.get()`.
741
+ * Never includes the raw key material — only the display prefix.
742
+ */
743
+ export interface KeyRecord {
744
+ /** Document ID. */
745
+ _id: string;
746
+ /** Owner user ID. */
747
+ userId: string;
748
+ /** Display prefix (e.g. `"sk_live_abc1"`). Safe to show in UIs. */
749
+ prefix: string;
750
+ /** Human-readable name (e.g. "CI Pipeline"). */
751
+ name: string;
752
+ /** Resource:action permissions granted to this key. */
753
+ scopes: KeyScope[];
754
+ /** Per-key rate limit, if configured. */
755
+ rateLimit?: { maxRequests: number; windowMs: number };
756
+ /** Expiration timestamp (ms since epoch), or `undefined` for no expiry. */
757
+ expiresAt?: number;
758
+ /** Timestamp of last successful verification, or `undefined` if never used. */
759
+ lastUsedAt?: number;
760
+ /** Creation timestamp (ms since epoch). */
761
+ createdAt: number;
762
+ /** `true` when the key has been revoked (soft-deleted). */
763
+ revoked: boolean;
764
+ }
765
+
527
766
  /**
528
767
  * Component function references required by core auth runtime.
768
+ *
769
+ * @internal Consumers should not depend on this shape — it may change
770
+ * between minor versions. Pass `components.auth` directly to the `Auth` constructor.
529
771
  */
530
772
  export type AuthComponentApi = {
531
773
  public: {
@@ -582,6 +824,13 @@ export type AuthComponentApi = {
582
824
  inviteList: FunctionReference<"query", "internal">;
583
825
  inviteAccept: FunctionReference<"mutation", "internal">;
584
826
  inviteRevoke: FunctionReference<"mutation", "internal">;
827
+ keyInsert: FunctionReference<"mutation", "internal">;
828
+ keyGetByHashedKey: FunctionReference<"query", "internal">;
829
+ keyGetById: FunctionReference<"query", "internal">;
830
+ keyList: FunctionReference<"query", "internal">;
831
+ keyListByUserId: FunctionReference<"query", "internal">;
832
+ keyPatch: FunctionReference<"mutation", "internal">;
833
+ keyDelete: FunctionReference<"mutation", "internal">;
585
834
  passkeyInsert: FunctionReference<"mutation", "internal">;
586
835
  passkeyGetByCredentialId: FunctionReference<"query", "internal">;
587
836
  passkeyListByUserId: FunctionReference<"query", "internal">;
@@ -1,7 +1,9 @@
1
+ import { throwAuthError } from "./errors.js";
2
+
1
3
  export function requireEnv(name: string) {
2
4
  const value = process.env[name];
3
5
  if (value === undefined) {
4
- throw new Error(`Missing environment variable \`${name}\``);
6
+ throwAuthError("MISSING_ENV_VAR", `Missing environment variable \`${name}\``, { variable: name });
5
7
  }
6
8
  return value;
7
9
  }
@@ -0,0 +1,2 @@
1
+ // Auto-generated by scripts/generate-version.js — do not edit.
2
+ export const AUTH_VERSION = "0.0.3-preview.1";
@@ -1,116 +0,0 @@
1
- import type { HttpRouter } from "convex/server";
2
- import type { ComponentApi as AuthComponentApi } from "../component/_generated/component.js";
3
- /**
4
- * Configure the Convex Auth Portal. Returns all the functions needed to
5
- * serve the portal admin UI, manage invite links, and query auth data.
6
- *
7
- * The portal dogfoods the same `Auth()` instance as your app. Portal admins
8
- * sign in via email magic link and are identified by accepted invites with
9
- * `role: "portalAdmin"`.
10
- *
11
- * ```ts filename="convex/portal.ts"
12
- * import { Portal } from "@robelest/convex-auth/component";
13
- * import { auth } from "./auth";
14
- * import { components } from "./_generated/api";
15
- *
16
- * export const {
17
- * hosting, getCurrentDeployment,
18
- * portalQuery, portalMutation,
19
- * validateInvite, acceptInvite, createPortalInvite,
20
- * portal,
21
- * } = Portal(components.auth, components.selfHosting, auth);
22
- * ```
23
- *
24
- * ## Setup
25
- *
26
- * 1. Configure an email provider in your `Auth()` config (e.g. Resend).
27
- * 2. Generate an admin invite link:
28
- * `npx @robelest/convex-auth portal link [--prod]`
29
- * 3. Visit the link, enter your email, click the magic link, and you're in.
30
- *
31
- * The portal URL is auto-derived from `CONVEX_SITE_URL` (always set by Convex).
32
- * Override with `options.portalUrl` if you need a custom URL.
33
- */
34
- export declare function Portal(authComponent: AuthComponentApi, selfHostingComponent: any, auth: any, options?: {
35
- portalUrl?: string;
36
- }): {
37
- /**
38
- * Combined internal mutation for self-hosting operations.
39
- * Used by the CLI (`@robelest/convex-auth portal upload`) to
40
- * upload static assets and manage deployments.
41
- */
42
- hosting: import("convex/server").RegisteredMutation<"internal", any, Promise<any>>;
43
- getCurrentDeployment: import("convex/server").RegisteredQuery<"public", {}, Promise<any>>;
44
- /**
45
- * Validate an invite token. Returns the invite if valid and pending,
46
- * or `null` otherwise. Used by the portal UI to check if an invite
47
- * link is valid before showing the registration form.
48
- */
49
- validateInvite: import("convex/server").RegisteredQuery<"public", {
50
- tokenHash: string;
51
- }, Promise<{
52
- _id: any;
53
- role: any;
54
- } | null>>;
55
- /**
56
- * Accept a portal invite. Must be called by an authenticated user.
57
- * Marks the invite as accepted and records the accepting user's ID.
58
- *
59
- * The portal UI calls this after the user has signed in via magic link
60
- * following an invite link.
61
- */
62
- acceptInvite: import("convex/server").RegisteredMutation<"public", {
63
- tokenHash: string;
64
- }, Promise<void>>;
65
- /**
66
- * Create a portal admin invite. Internal mutation called by the CLI
67
- * (`npx @robelest/convex-auth portal link`).
68
- */
69
- createPortalInvite: import("convex/server").RegisteredMutation<"internal", {
70
- tokenHash: string;
71
- }, Promise<{
72
- portalUrl: string;
73
- }>>;
74
- /**
75
- * Combined portal query for all auth data reads.
76
- * Requires the caller to be an authenticated portal admin.
77
- *
78
- * Actions:
79
- * - `listUsers` — List all users
80
- * - `listSessions` — List all sessions
81
- * - `getUser` — Get a single user by ID (requires `userId`)
82
- * - `getUserSessions` — List sessions for a user (requires `userId`)
83
- * - `getUserAccounts` — List auth accounts for a user (requires `userId`)
84
- * - `isAdmin` — Check if the current user is a portal admin
85
- */
86
- portalQuery: import("convex/server").RegisteredQuery<"public", {
87
- action: string;
88
- userId?: string;
89
- }, Promise<any>>;
90
- /**
91
- * Combined portal mutation for all auth data writes.
92
- * Requires the caller to be an authenticated portal admin.
93
- *
94
- * Actions:
95
- * - `revokeSession` — Revoke (delete) a session (requires `sessionId`)
96
- */
97
- portalMutation: import("convex/server").RegisteredMutation<"public", {
98
- action: string;
99
- sessionId?: string;
100
- }, Promise<void>>;
101
- portal: {
102
- /**
103
- * The URL where the portal is served. Used by the Svelte client
104
- * as the `redirectTo` for magic link sign-in.
105
- */
106
- portalUrl: string;
107
- /**
108
- * Register HTTP routes that serve the portal static UI.
109
- */
110
- addHttpRoutes: (http: HttpRouter, opts?: {
111
- pathPrefix?: string;
112
- spaFallback?: boolean;
113
- }) => void;
114
- };
115
- };
116
- //# sourceMappingURL=portal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../src/server/portal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAiC7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CACpB,aAAa,EAAE,gBAAgB,EAC/B,oBAAoB,EAAE,GAAG,EACzB,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE;IAW9B;;;;OAIG;;;IAoFH;;;;OAIG;;mBAGqD,MAAM;;;;;IAe9D;;;;;;OAMG;;mBAGqD,MAAM;;IAwB9D;;;OAGG;;mBAGqD,MAAM;;;;IAY9D;;;;;;;;;;;OAWG;;gBAQ+B,MAAM;iBAAW,MAAM;;IAkDzD;;;;;;OAMG;;gBAQkC,MAAM;oBAAc,MAAM;;;QAqB7D;;;WAGG;;QAGH;;WAEG;8BAEK,UAAU,SACT;YAAE,UAAU,CAAC,EAAE,MAAM,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;;EAY5D"}