@robelest/convex-auth 0.0.4-preview.13 → 0.0.4-preview.16

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 (328) hide show
  1. package/README.md +140 -9
  2. package/dist/bin.cjs +5957 -5478
  3. package/dist/client/index.d.ts +3 -7
  4. package/dist/client/index.d.ts.map +1 -1
  5. package/dist/client/index.js +27 -26
  6. package/dist/client/index.js.map +1 -1
  7. package/dist/component/_generated/api.d.ts +14 -0
  8. package/dist/component/_generated/api.d.ts.map +1 -1
  9. package/dist/component/_generated/api.js.map +1 -1
  10. package/dist/component/_generated/component.d.ts +1672 -24
  11. package/dist/component/_generated/component.d.ts.map +1 -1
  12. package/dist/component/convex.config.d.ts +2 -2
  13. package/dist/component/convex.config.d.ts.map +1 -1
  14. package/dist/component/index.d.ts +1 -1
  15. package/dist/component/index.js +2 -2
  16. package/dist/component/model.d.ts +153 -0
  17. package/dist/component/model.d.ts.map +1 -0
  18. package/dist/component/model.js +343 -0
  19. package/dist/component/model.js.map +1 -0
  20. package/dist/component/providers/sso.d.ts +1 -1
  21. package/dist/component/public/enterprise.d.ts +54 -0
  22. package/dist/component/public/enterprise.d.ts.map +1 -0
  23. package/dist/component/public/enterprise.js +515 -0
  24. package/dist/component/public/enterprise.js.map +1 -0
  25. package/dist/component/public/factors.d.ts +52 -0
  26. package/dist/component/public/factors.d.ts.map +1 -0
  27. package/dist/component/public/factors.js +285 -0
  28. package/dist/component/public/factors.js.map +1 -0
  29. package/dist/component/public/groups.d.ts +116 -0
  30. package/dist/component/public/groups.d.ts.map +1 -0
  31. package/dist/component/public/groups.js +596 -0
  32. package/dist/component/public/groups.js.map +1 -0
  33. package/dist/component/public/identity.d.ts +93 -0
  34. package/dist/component/public/identity.d.ts.map +1 -0
  35. package/dist/component/public/identity.js +426 -0
  36. package/dist/component/public/identity.js.map +1 -0
  37. package/dist/component/public/keys.d.ts +41 -0
  38. package/dist/component/public/keys.d.ts.map +1 -0
  39. package/dist/component/public/keys.js +157 -0
  40. package/dist/component/public/keys.js.map +1 -0
  41. package/dist/component/public/shared.d.ts +26 -0
  42. package/dist/component/public/shared.d.ts.map +1 -0
  43. package/dist/component/public/shared.js +32 -0
  44. package/dist/component/public/shared.js.map +1 -0
  45. package/dist/component/public.d.ts +9 -321
  46. package/dist/component/public.d.ts.map +1 -1
  47. package/dist/component/public.js +6 -2145
  48. package/dist/component/schema.d.ts +406 -260
  49. package/dist/component/schema.js +37 -32
  50. package/dist/component/schema.js.map +1 -1
  51. package/dist/component/server/auth.d.ts +161 -15
  52. package/dist/component/server/auth.d.ts.map +1 -1
  53. package/dist/component/server/auth.js +100 -7
  54. package/dist/component/server/auth.js.map +1 -1
  55. package/dist/component/server/cookies.js +3 -0
  56. package/dist/component/server/cookies.js.map +1 -1
  57. package/dist/component/server/db.js +1 -0
  58. package/dist/component/server/db.js.map +1 -1
  59. package/dist/component/server/device.js +3 -1
  60. package/dist/component/server/device.js.map +1 -1
  61. package/dist/component/server/domains/core.js +629 -0
  62. package/dist/component/server/domains/core.js.map +1 -0
  63. package/dist/component/server/domains/sso.js +884 -0
  64. package/dist/component/server/domains/sso.js.map +1 -0
  65. package/dist/component/server/factory.d.ts +136 -0
  66. package/dist/component/server/factory.d.ts.map +1 -0
  67. package/dist/component/server/factory.js +1134 -0
  68. package/dist/component/server/factory.js.map +1 -0
  69. package/dist/component/server/fx.js +2 -1
  70. package/dist/component/server/fx.js.map +1 -1
  71. package/dist/component/server/http.js +287 -0
  72. package/dist/component/server/http.js.map +1 -0
  73. package/dist/component/server/identity.js +13 -0
  74. package/dist/component/server/identity.js.map +1 -0
  75. package/dist/component/server/keys.js +4 -0
  76. package/dist/component/server/keys.js.map +1 -1
  77. package/dist/component/server/mutations/account.js +1 -1
  78. package/dist/component/server/mutations/index.js +2 -2
  79. package/dist/component/server/mutations/index.js.map +1 -1
  80. package/dist/component/server/mutations/invalidate.js +1 -1
  81. package/dist/component/server/mutations/oauth.js +10 -7
  82. package/dist/component/server/mutations/oauth.js.map +1 -1
  83. package/dist/component/server/mutations/refresh.js +1 -1
  84. package/dist/component/server/mutations/register.js +1 -1
  85. package/dist/component/server/mutations/retrieve.js +1 -1
  86. package/dist/component/server/mutations/signature.js +1 -1
  87. package/dist/component/server/mutations/store.js +6 -3
  88. package/dist/component/server/mutations/store.js.map +1 -1
  89. package/dist/component/server/mutations/verify.js +1 -1
  90. package/dist/component/server/oauth.js +3 -0
  91. package/dist/component/server/oauth.js.map +1 -1
  92. package/dist/component/server/passkey.js +3 -2
  93. package/dist/component/server/passkey.js.map +1 -1
  94. package/dist/component/server/provider.js +2 -0
  95. package/dist/component/server/provider.js.map +1 -1
  96. package/dist/component/server/providers.js +10 -0
  97. package/dist/component/server/providers.js.map +1 -1
  98. package/dist/component/server/ratelimit.js +3 -0
  99. package/dist/component/server/ratelimit.js.map +1 -1
  100. package/dist/component/server/redirects.js +2 -0
  101. package/dist/component/server/redirects.js.map +1 -1
  102. package/dist/component/server/refresh.js +5 -0
  103. package/dist/component/server/refresh.js.map +1 -1
  104. package/dist/component/server/sessions.js +5 -0
  105. package/dist/component/server/sessions.js.map +1 -1
  106. package/dist/component/server/signin.js +2 -1
  107. package/dist/component/server/signin.js.map +1 -1
  108. package/dist/component/server/sso.js +166 -19
  109. package/dist/component/server/sso.js.map +1 -1
  110. package/dist/component/server/tokens.js +1 -0
  111. package/dist/component/server/tokens.js.map +1 -1
  112. package/dist/component/server/totp.js +4 -2
  113. package/dist/component/server/totp.js.map +1 -1
  114. package/dist/component/server/types.d.ts +106 -38
  115. package/dist/component/server/types.d.ts.map +1 -1
  116. package/dist/component/server/types.js.map +1 -1
  117. package/dist/component/server/users.js +1 -0
  118. package/dist/component/server/users.js.map +1 -1
  119. package/dist/component/server/utils.js +44 -2
  120. package/dist/component/server/utils.js.map +1 -1
  121. package/dist/providers/anonymous.d.ts +1 -1
  122. package/dist/providers/credentials.d.ts +1 -1
  123. package/dist/providers/password.d.ts +1 -1
  124. package/dist/providers/sso.d.ts +1 -1
  125. package/dist/providers/sso.js.map +1 -1
  126. package/dist/server/auth.d.ts +163 -17
  127. package/dist/server/auth.d.ts.map +1 -1
  128. package/dist/server/auth.js +100 -7
  129. package/dist/server/auth.js.map +1 -1
  130. package/dist/server/cookies.d.ts +1 -38
  131. package/dist/server/cookies.js +3 -0
  132. package/dist/server/cookies.js.map +1 -1
  133. package/dist/server/db.d.ts +1 -125
  134. package/dist/server/db.js +1 -0
  135. package/dist/server/db.js.map +1 -1
  136. package/dist/server/device.d.ts +1 -24
  137. package/dist/server/device.js +3 -1
  138. package/dist/server/device.js.map +1 -1
  139. package/dist/server/domains/core.d.ts +434 -0
  140. package/dist/server/domains/core.d.ts.map +1 -0
  141. package/dist/server/domains/core.js +629 -0
  142. package/dist/server/domains/core.js.map +1 -0
  143. package/dist/server/domains/sso.d.ts +409 -0
  144. package/dist/server/domains/sso.d.ts.map +1 -0
  145. package/dist/server/domains/sso.js +884 -0
  146. package/dist/server/domains/sso.js.map +1 -0
  147. package/dist/server/enterpriseValidators.d.ts +1 -0
  148. package/dist/server/enterpriseValidators.js +60 -0
  149. package/dist/server/enterpriseValidators.js.map +1 -0
  150. package/dist/server/factory.d.ts +136 -0
  151. package/dist/server/factory.d.ts.map +1 -0
  152. package/dist/server/factory.js +1134 -0
  153. package/dist/server/factory.js.map +1 -0
  154. package/dist/server/fx.d.ts +1 -16
  155. package/dist/server/fx.d.ts.map +1 -1
  156. package/dist/server/fx.js +1 -0
  157. package/dist/server/fx.js.map +1 -1
  158. package/dist/server/http.d.ts +59 -0
  159. package/dist/server/http.d.ts.map +1 -0
  160. package/dist/server/http.js +287 -0
  161. package/dist/server/http.js.map +1 -0
  162. package/dist/server/identity.d.ts +1 -0
  163. package/dist/server/identity.js +13 -0
  164. package/dist/server/identity.js.map +1 -0
  165. package/dist/server/index.d.ts +468 -1
  166. package/dist/server/index.d.ts.map +1 -1
  167. package/dist/server/index.js +530 -36
  168. package/dist/server/index.js.map +1 -1
  169. package/dist/server/keys.d.ts +1 -57
  170. package/dist/server/keys.js +4 -0
  171. package/dist/server/keys.js.map +1 -1
  172. package/dist/server/mutations/account.d.ts +7 -7
  173. package/dist/server/mutations/account.d.ts.map +1 -1
  174. package/dist/server/mutations/code.d.ts +13 -13
  175. package/dist/server/mutations/code.d.ts.map +1 -1
  176. package/dist/server/mutations/index.d.ts +107 -107
  177. package/dist/server/mutations/index.d.ts.map +1 -1
  178. package/dist/server/mutations/index.js +1 -1
  179. package/dist/server/mutations/index.js.map +1 -1
  180. package/dist/server/mutations/invalidate.d.ts +5 -5
  181. package/dist/server/mutations/invalidate.d.ts.map +1 -1
  182. package/dist/server/mutations/oauth.d.ts +10 -10
  183. package/dist/server/mutations/oauth.d.ts.map +1 -1
  184. package/dist/server/mutations/oauth.js +9 -6
  185. package/dist/server/mutations/oauth.js.map +1 -1
  186. package/dist/server/mutations/refresh.d.ts +4 -4
  187. package/dist/server/mutations/register.d.ts +12 -12
  188. package/dist/server/mutations/register.d.ts.map +1 -1
  189. package/dist/server/mutations/retrieve.d.ts +7 -7
  190. package/dist/server/mutations/signature.d.ts +5 -5
  191. package/dist/server/mutations/signin.d.ts +6 -6
  192. package/dist/server/mutations/signin.d.ts.map +1 -1
  193. package/dist/server/mutations/signout.d.ts +1 -1
  194. package/dist/server/mutations/store.d.ts +3 -2
  195. package/dist/server/mutations/store.d.ts.map +1 -1
  196. package/dist/server/mutations/store.js +6 -3
  197. package/dist/server/mutations/store.js.map +1 -1
  198. package/dist/server/mutations/verifier.d.ts +1 -1
  199. package/dist/server/mutations/verify.d.ts +11 -11
  200. package/dist/server/mutations/verify.d.ts.map +1 -1
  201. package/dist/server/oauth.d.ts +1 -59
  202. package/dist/server/oauth.js +3 -0
  203. package/dist/server/oauth.js.map +1 -1
  204. package/dist/server/passkey.d.ts.map +1 -1
  205. package/dist/server/passkey.js +3 -2
  206. package/dist/server/passkey.js.map +1 -1
  207. package/dist/server/provider.d.ts +1 -14
  208. package/dist/server/provider.d.ts.map +1 -1
  209. package/dist/server/provider.js +2 -0
  210. package/dist/server/provider.js.map +1 -1
  211. package/dist/server/providers.js +10 -0
  212. package/dist/server/providers.js.map +1 -1
  213. package/dist/server/ratelimit.d.ts +1 -22
  214. package/dist/server/ratelimit.js +3 -0
  215. package/dist/server/ratelimit.js.map +1 -1
  216. package/dist/server/redirects.d.ts +1 -10
  217. package/dist/server/redirects.js +2 -0
  218. package/dist/server/redirects.js.map +1 -1
  219. package/dist/server/refresh.d.ts +1 -37
  220. package/dist/server/refresh.js +5 -0
  221. package/dist/server/refresh.js.map +1 -1
  222. package/dist/server/sessions.d.ts +1 -28
  223. package/dist/server/sessions.js +5 -0
  224. package/dist/server/sessions.js.map +1 -1
  225. package/dist/server/signin.d.ts +1 -55
  226. package/dist/server/signin.js +2 -1
  227. package/dist/server/signin.js.map +1 -1
  228. package/dist/server/sso.d.ts +1 -348
  229. package/dist/server/sso.js +165 -18
  230. package/dist/server/sso.js.map +1 -1
  231. package/dist/server/templates.d.ts +1 -21
  232. package/dist/server/templates.js +1 -0
  233. package/dist/server/templates.js.map +1 -1
  234. package/dist/server/tokens.d.ts +1 -11
  235. package/dist/server/tokens.js +1 -0
  236. package/dist/server/tokens.js.map +1 -1
  237. package/dist/server/totp.d.ts +1 -23
  238. package/dist/server/totp.js +4 -2
  239. package/dist/server/totp.js.map +1 -1
  240. package/dist/server/types.d.ts +114 -77
  241. package/dist/server/types.d.ts.map +1 -1
  242. package/dist/server/types.js.map +1 -1
  243. package/dist/server/users.d.ts +1 -31
  244. package/dist/server/users.js +1 -0
  245. package/dist/server/users.js.map +1 -1
  246. package/dist/server/utils.d.ts +1 -27
  247. package/dist/server/utils.js +44 -2
  248. package/dist/server/utils.js.map +1 -1
  249. package/dist/server/version.d.ts +1 -1
  250. package/dist/server/version.js +1 -1
  251. package/dist/server/version.js.map +1 -1
  252. package/package.json +4 -5
  253. package/src/cli/bin.ts +5 -0
  254. package/src/cli/index.ts +22 -9
  255. package/src/cli/keys.ts +3 -0
  256. package/src/client/index.ts +36 -37
  257. package/src/component/_generated/api.ts +14 -0
  258. package/src/component/_generated/component.ts +2106 -9
  259. package/src/component/index.ts +3 -1
  260. package/src/component/model.ts +441 -0
  261. package/src/component/public/enterprise.ts +753 -0
  262. package/src/component/public/factors.ts +332 -0
  263. package/src/component/public/groups.ts +932 -0
  264. package/src/component/public/identity.ts +566 -0
  265. package/src/component/public/keys.ts +209 -0
  266. package/src/component/public/shared.ts +119 -0
  267. package/src/component/public.ts +5 -2965
  268. package/src/component/schema.ts +68 -63
  269. package/src/providers/sso.ts +1 -1
  270. package/src/server/auth.ts +413 -18
  271. package/src/server/cookies.ts +3 -0
  272. package/src/server/db.ts +3 -0
  273. package/src/server/device.ts +3 -1
  274. package/src/server/domains/core.ts +1071 -0
  275. package/src/server/domains/sso.ts +1749 -0
  276. package/src/server/enterpriseValidators.ts +93 -0
  277. package/src/server/factory.ts +2181 -0
  278. package/src/server/fx.ts +1 -0
  279. package/src/server/http.ts +529 -0
  280. package/src/server/identity.ts +18 -0
  281. package/src/server/index.ts +806 -40
  282. package/src/server/keys.ts +4 -0
  283. package/src/server/mutations/index.ts +1 -1
  284. package/src/server/mutations/oauth.ts +36 -8
  285. package/src/server/mutations/store.ts +6 -3
  286. package/src/server/oauth.ts +6 -0
  287. package/src/server/passkey.ts +3 -2
  288. package/src/server/provider.ts +2 -0
  289. package/src/server/providers.ts +20 -0
  290. package/src/server/ratelimit.ts +3 -0
  291. package/src/server/redirects.ts +2 -0
  292. package/src/server/refresh.ts +5 -0
  293. package/src/server/sessions.ts +5 -0
  294. package/src/server/signin.ts +1 -0
  295. package/src/server/sso.ts +259 -17
  296. package/src/server/templates.ts +1 -0
  297. package/src/server/tokens.ts +1 -0
  298. package/src/server/totp.ts +4 -2
  299. package/src/server/types.ts +178 -83
  300. package/src/server/users.ts +1 -0
  301. package/src/server/utils.ts +71 -1
  302. package/src/server/version.ts +1 -1
  303. package/dist/component/public.js.map +0 -1
  304. package/dist/component/server/implementation.d.ts +0 -1264
  305. package/dist/component/server/implementation.d.ts.map +0 -1
  306. package/dist/component/server/implementation.js +0 -2365
  307. package/dist/component/server/implementation.js.map +0 -1
  308. package/dist/server/cookies.d.ts.map +0 -1
  309. package/dist/server/db.d.ts.map +0 -1
  310. package/dist/server/device.d.ts.map +0 -1
  311. package/dist/server/implementation.d.ts +0 -1264
  312. package/dist/server/implementation.d.ts.map +0 -1
  313. package/dist/server/implementation.js +0 -2365
  314. package/dist/server/implementation.js.map +0 -1
  315. package/dist/server/keys.d.ts.map +0 -1
  316. package/dist/server/oauth.d.ts.map +0 -1
  317. package/dist/server/ratelimit.d.ts.map +0 -1
  318. package/dist/server/redirects.d.ts.map +0 -1
  319. package/dist/server/refresh.d.ts.map +0 -1
  320. package/dist/server/sessions.d.ts.map +0 -1
  321. package/dist/server/signin.d.ts.map +0 -1
  322. package/dist/server/sso.d.ts.map +0 -1
  323. package/dist/server/templates.d.ts.map +0 -1
  324. package/dist/server/tokens.d.ts.map +0 -1
  325. package/dist/server/totp.d.ts.map +0 -1
  326. package/dist/server/users.d.ts.map +0 -1
  327. package/dist/server/utils.d.ts.map +0 -1
  328. package/src/server/implementation.ts +0 -5336
@@ -1,1264 +0,0 @@
1
- import { AuthProviderConfig, ConvexAuthConfig, CorsConfig, Doc, HttpKeyContext, KeyDoc, KeyScope, ScopeChecker, SessionInfo, UserOrderBy, UserWhere } from "./types.js";
2
- import * as convex_server23 from "convex/server";
3
- import { GenericActionCtx, GenericDataModel, HttpRouter } from "convex/server";
4
- import { GenericId } from "convex/values";
5
-
6
- //#region src/server/implementation.d.ts
7
- /**
8
- * Configure the Convex Auth library. Returns an object with
9
- * functions and `auth` helper. You must export the functions
10
- * from `convex/auth.ts` to make them callable:
11
- *
12
- * ```ts filename="convex/auth.ts"
13
- * import { createAuth } from "@robelest/convex-auth/component";
14
- * import { components } from "./_generated/api";
15
- *
16
- * export const auth = createAuth(components.auth, {
17
- * providers: [],
18
- * });
19
- * export const { signIn, signOut, store } = auth;
20
- * ```
21
- *
22
- * @returns An object with fields you should reexport from your
23
- * `convex/auth.ts` file.
24
- */
25
- declare function Auth(config_: ConvexAuthConfig): {
26
- /**
27
- * Helper for configuring HTTP actions.
28
- */
29
- auth: {
30
- user: {
31
- /**
32
- * Get the current user's ID, or `null` if not signed in.
33
- *
34
- * Tries session JWT first. If `request` is provided, falls back to
35
- * verifying an `Authorization: Bearer sk_...` API key header.
36
- *
37
- * @param ctx - Any Convex context with an `auth` field.
38
- * @param request - Optional `Request`; enables API key fallback.
39
- * @returns The user's ID string, or `null` when unauthenticated.
40
- */
41
- current: (ctx: {
42
- auth: Auth;
43
- } & Partial<Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">>, request?: Request) => Promise<string | null>;
44
- /**
45
- * Get the current user's ID, or throw `NOT_SIGNED_IN` if not signed in.
46
- *
47
- * Tries session JWT first. If `request` is provided, falls back to
48
- * verifying an `Authorization: Bearer sk_...` API key header.
49
- *
50
- * @param ctx - Any Convex context with an `auth` field.
51
- * @param request - Optional `Request`; enables API key fallback.
52
- * @returns The user's ID string.
53
- * @throws `ConvexError` with code `NOT_SIGNED_IN` when unauthenticated.
54
- */
55
- require: (ctx: {
56
- auth: Auth;
57
- } & Partial<Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">>, request?: Request) => Promise<string>;
58
- /**
59
- * Retrieve a user document by their ID.
60
- *
61
- * @param ctx - Convex context with `runQuery`.
62
- * @param userId - The user document ID.
63
- * @returns The user document, or `null` if not found.
64
- */
65
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, userId: string) => Promise<any>;
66
- /**
67
- * List users with optional filters, sorting, and pagination.
68
- *
69
- * @param opts.where - Optional filters (email, phone, name, anonymous).
70
- * @param opts.limit - Max users to return (default 50).
71
- * @param opts.cursor - Pagination cursor from a previous page.
72
- * @param opts.orderBy - Sort field.
73
- * @param opts.order - Sort direction.
74
- * @returns `{ items, nextCursor }`.
75
- */
76
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
77
- where?: UserWhere;
78
- limit?: number;
79
- cursor?: string | null;
80
- orderBy?: UserOrderBy;
81
- order?: "asc" | "desc";
82
- }) => Promise<any>;
83
- /**
84
- * Get the currently signed-in user's document, or `null` if not
85
- * signed in. Convenience combining `current()` + `get()`.
86
- *
87
- * @param ctx - Convex context with `auth` and `runQuery`.
88
- * @returns The user document, or `null` when unauthenticated.
89
- */
90
- viewer: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery"> & {
91
- auth: Auth;
92
- }) => Promise<any>;
93
- /**
94
- * Update a user document with partial data.
95
- *
96
- * @param ctx - Convex context with `runMutation`.
97
- * @param userId - The user document ID.
98
- * @param data - Partial data to merge into the user document.
99
- */
100
- patch: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, userId: string, data: Record<string, unknown>) => Promise<void>;
101
- /**
102
- * Set or clear a user's active group in `user.extend.lastActiveGroup`.
103
- *
104
- * This helper preserves other keys under `user.extend`.
105
- * Pass `groupId: null` to clear `lastActiveGroup`.
106
- */
107
- setActiveGroup: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, opts: {
108
- userId: string;
109
- groupId: string | null;
110
- }) => Promise<void>;
111
- /**
112
- * Get the user's active group ID from `user.extend.lastActiveGroup`.
113
- *
114
- * @param ctx - Convex context with `runQuery`.
115
- * @param opts.userId - The user document ID.
116
- * @returns The active group ID, or `null` if none is set.
117
- */
118
- getActiveGroup: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
119
- userId: string;
120
- }) => Promise<string | null>;
121
- /**
122
- * Delete a user and optionally cascade-delete all linked records.
123
- *
124
- * When `cascade` is `true` (default), this removes all sessions,
125
- * accounts, API keys, group memberships, passkeys, and TOTP
126
- * enrollments before deleting the user document itself.
127
- *
128
- * When `cascade` is `false`, the method throws if the user has any
129
- * linked records — the caller must clean them up explicitly first.
130
- *
131
- * @param ctx - Convex action context with `runMutation` and `runQuery`.
132
- * @param userId - The user document ID to delete.
133
- * @param opts.cascade - Whether to cascade-delete linked records (default: `true`).
134
- */
135
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, userId: string, opts?: {
136
- cascade?: boolean;
137
- }) => Promise<void>;
138
- };
139
- session: {
140
- /**
141
- * Get the current session ID from the auth context, or `null` if
142
- * not signed in.
143
- *
144
- * @param ctx - Any Convex context with an `auth` field.
145
- * @returns The session's `Id<"Session">`, or `null` when unauthenticated.
146
- */
147
- current: (ctx: {
148
- auth: Auth;
149
- }) => Promise<GenericId<"Session"> | null>;
150
- /**
151
- * Invalidate sessions for a user, optionally preserving specific sessions.
152
- *
153
- * @param ctx - Convex action context.
154
- * @param args.userId - The user whose sessions to invalidate.
155
- * @param args.except - Session IDs to preserve (e.g. the current session).
156
- */
157
- invalidate: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
158
- userId: GenericId<"User">;
159
- except?: GenericId<"Session">[];
160
- }) => Promise<void>;
161
- /**
162
- * Get a session by its document ID.
163
- *
164
- * @param ctx - Convex context with `runQuery`.
165
- * @param sessionId - The session document ID.
166
- * @returns The session document, or `null` if not found.
167
- */
168
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, sessionId: string) => Promise<any>;
169
- /**
170
- * List all active sessions for a user.
171
- *
172
- * @param ctx - Convex context with `runQuery`.
173
- * @param opts.userId - The user whose sessions to list.
174
- * @returns Array of session documents.
175
- */
176
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
177
- userId: string;
178
- }) => Promise<any>;
179
- };
180
- account: {
181
- /**
182
- * Create an account and user for a credentials provider.
183
- *
184
- * @param ctx - Convex action context.
185
- * @param args - Provider ID, account credentials, profile data, and link flags.
186
- * @returns `{ account, user }` — the created account and user documents.
187
- */
188
- create: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
189
- provider: string;
190
- account: {
191
- id: string;
192
- secret?: string;
193
- };
194
- profile: Record<string, unknown>;
195
- shouldLinkViaEmail?: boolean;
196
- shouldLinkViaPhone?: boolean;
197
- }) => Promise<{
198
- account: Doc<"Account">;
199
- user: Doc<"User">;
200
- }>;
201
- /**
202
- * Retrieve an account and user for a credentials provider.
203
- *
204
- * @param ctx - Convex action context.
205
- * @param args - Provider ID and account credentials (id, optional secret).
206
- * @returns `{ account, user }` — the matched account and user documents.
207
- * @throws `ConvexError` with code `ACCOUNT_NOT_FOUND` when no match exists.
208
- */
209
- get: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
210
- provider: string;
211
- account: {
212
- id: string;
213
- secret?: string;
214
- };
215
- }) => Promise<{
216
- account: Doc<"Account">;
217
- user: Doc<"User">;
218
- }>;
219
- /**
220
- * Update account credentials (secret) for an existing account.
221
- *
222
- * @param ctx - Convex action context.
223
- * @param args - Provider ID and new account credentials (id + secret).
224
- */
225
- update: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
226
- provider: string;
227
- account: {
228
- id: string;
229
- secret: string;
230
- };
231
- }) => Promise<void>;
232
- /**
233
- * Unlink (delete) an account from a user.
234
- *
235
- * Throws if the account is the user's only account and the user has
236
- * no other way to sign in (prevents locking the user out).
237
- *
238
- * @param ctx - Convex context with `runQuery` and `runMutation`.
239
- * @param accountId - The account document ID to unlink.
240
- */
241
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, accountId: string) => Promise<void>; /** List all passkeys for a user. */
242
- listPasskeys: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
243
- userId: string;
244
- }) => Promise<any>; /** Rename a passkey (set a user-friendly display name). */
245
- renamePasskey: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, passkeyId: string, name: string) => Promise<void>; /** Delete a passkey credential. */
246
- removePasskey: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, passkeyId: string) => Promise<void>; /** List all TOTP enrollments for a user. */
247
- listTotps: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
248
- userId: string;
249
- }) => Promise<any>; /** Delete a TOTP enrollment. */
250
- removeTotp: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, totpId: string) => Promise<void>;
251
- };
252
- provider: {
253
- /**
254
- * Sign in via another provider, typically from a credentials flow.
255
- *
256
- * @param ctx - Convex action context.
257
- * @param provider - The provider config to sign in with.
258
- * @param args - Optional account ID and params.
259
- * @returns `{ userId, sessionId }` on success, or `null`.
260
- */
261
- signIn: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, provider: AuthProviderConfig, args: {
262
- accountId?: GenericId<"Account">;
263
- params?: Record<string, unknown>;
264
- }) => Promise<{
265
- userId: GenericId<"User">;
266
- sessionId: GenericId<"Session">;
267
- } | null>;
268
- };
269
- /**
270
- * Hierarchical group management. Groups can nest arbitrarily deep
271
- * via `parentGroupId`. A root group has no parent.
272
- *
273
- * ```ts
274
- * const groupId = await auth.group.create(ctx, { name: "Acme Corp" });
275
- * const subGroupId = await auth.group.create(ctx, {
276
- * name: "Engineering",
277
- * parentGroupId: groupId,
278
- * });
279
- * ```
280
- */
281
- group: {
282
- /**
283
- * Create a new group. Omit `parentGroupId` for a root-level group,
284
- * or provide it to create a nested group.
285
- *
286
- * @returns The ID of the newly created group.
287
- */
288
- create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
289
- name: string;
290
- slug?: string;
291
- type?: string;
292
- parentGroupId?: string;
293
- tags?: Array<{
294
- key: string;
295
- value: string;
296
- }>;
297
- extend?: Record<string, unknown>;
298
- }) => Promise<string>;
299
- /**
300
- * Retrieve a group by its ID. Returns `null` if not found.
301
- */
302
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, groupId: string) => Promise<any>;
303
- /**
304
- * List groups with optional filtering, sorting, and pagination.
305
- *
306
- * Empty `where` returns **all** groups.
307
- *
308
- * ```ts
309
- * // All groups of type "team"
310
- * await auth.group.list(ctx, { where: { type: "team" } });
311
- *
312
- * // Paginated
313
- * const page1 = await auth.group.list(ctx, { limit: 10 });
314
- * const page2 = await auth.group.list(ctx, { limit: 10, cursor: page1.nextCursor });
315
- * ```
316
- */
317
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
318
- where?: {
319
- slug?: string;
320
- type?: string;
321
- parentGroupId?: string;
322
- name?: string;
323
- isRoot?: boolean;
324
- tagsAll?: Array<{
325
- key: string;
326
- value: string;
327
- }>;
328
- tagsAny?: Array<{
329
- key: string;
330
- value: string;
331
- }>;
332
- };
333
- limit?: number;
334
- cursor?: string | null;
335
- orderBy?: "_creationTime" | "name" | "slug" | "type";
336
- order?: "asc" | "desc";
337
- }) => Promise<any>;
338
- /**
339
- * Update a group's fields (name, slug, tags, extend, parentGroupId).
340
- */
341
- update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, groupId: string, data: Record<string, unknown>) => Promise<void>;
342
- /**
343
- * Delete a group and cascade to all descendants. Deletes child groups
344
- * (recursively), all members, and all invites for this group and its
345
- * descendants.
346
- */
347
- delete: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, groupId: string) => Promise<void>;
348
- /**
349
- * Retrieve the ancestor chain for a group by walking `parentGroupId`
350
- * upward toward the root.
351
- *
352
- * Useful for breadcrumbs, permission inheritance visualization, and
353
- * operations that need the full hierarchy path.
354
- *
355
- * @param ctx - Convex context with `runQuery`.
356
- * @param opts.groupId - The starting group.
357
- * @param opts.maxDepth - Maximum traversal depth (default 32).
358
- * @param opts.includeSelf - Include the starting group as the first
359
- * element (default `false`).
360
- * @returns Ancestors ordered from immediate parent to root, plus
361
- * diagnostic flags.
362
- */
363
- ancestors: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
364
- groupId: string;
365
- maxDepth?: number;
366
- includeSelf?: boolean;
367
- }) => Promise<{
368
- ancestors: any[];
369
- cycleDetected: boolean;
370
- maxDepthReached: boolean;
371
- }>;
372
- };
373
- /**
374
- * Manage group membership. A member links a user to a group with an
375
- * application-defined role string (e.g. "owner", "admin", "member").
376
- *
377
- * The auth component stores roles but does not enforce access control.
378
- * Your application defines what each role means.
379
- */
380
- member: {
381
- /**
382
- * Add a user as a member of a group.
383
- *
384
- * @param data.groupId - The group to add the member to.
385
- * @param data.userId - The user to add.
386
- * @param data.role - Application-defined role (e.g. "owner", "admin", "member").
387
- * @param data.status - Optional membership status (e.g. "active", "suspended").
388
- * @param data.extend - Optional arbitrary JSON extension data.
389
- * @throws ConvexError with code `DUPLICATE_MEMBERSHIP` if the user is
390
- * already a member of the target group.
391
- * @returns The ID of the new member record.
392
- */
393
- add: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
394
- groupId: string;
395
- userId: string;
396
- role?: string;
397
- status?: string;
398
- extend?: Record<string, unknown>;
399
- }) => Promise<string>;
400
- /**
401
- * Retrieve a member record by its ID. Returns `null` if not found.
402
- */
403
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, memberId: string) => Promise<any>;
404
- /**
405
- * Look up a user's membership in a specific group.
406
- */
407
- getByUserAndGroup: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
408
- userId: string;
409
- groupId: string;
410
- }) => Promise<any>;
411
- /**
412
- * List members with optional filtering, sorting, and pagination.
413
- *
414
- * ```ts
415
- * // All members of a group
416
- * await auth.member.list(ctx, { where: { groupId } });
417
- *
418
- * // Admins only
419
- * await auth.member.list(ctx, { where: { groupId, role: "admin" } });
420
- * ```
421
- */
422
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
423
- where?: {
424
- groupId?: string;
425
- userId?: string;
426
- role?: string;
427
- status?: string;
428
- };
429
- limit?: number;
430
- cursor?: string | null;
431
- orderBy?: "_creationTime" | "role" | "status";
432
- order?: "asc" | "desc";
433
- }) => Promise<any>;
434
- /**
435
- * Remove a member from a group by deleting the member record.
436
- */
437
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, memberId: string) => Promise<void>;
438
- /**
439
- * Update a member's fields (role, status, extend).
440
- */
441
- update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, memberId: string, data: Record<string, unknown>) => Promise<void>;
442
- /**
443
- * Resolve membership for a group, including inherited membership
444
- * from ancestor groups (`parentGroupId` chain).
445
- *
446
- * Returns direct membership when found on `opts.groupId`, otherwise
447
- * returns the nearest ancestor membership. Use `roles` to only match
448
- * specific roles (for example `admin`/`lead`).
449
- */
450
- inherit: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
451
- userId: string;
452
- groupId: string;
453
- roles?: string[];
454
- maxDepth?: number;
455
- }) => Promise<{
456
- requestedGroupId: string;
457
- matchedGroupId: string;
458
- membership: any;
459
- depth: number;
460
- isDirect: boolean;
461
- isInherited: boolean;
462
- traversedGroupIds: string[];
463
- cycleDetected: boolean;
464
- maxDepthReached: boolean;
465
- } | {
466
- requestedGroupId: string;
467
- matchedGroupId: null;
468
- membership: null;
469
- depth: null;
470
- isDirect: boolean;
471
- isInherited: boolean;
472
- traversedGroupIds: string[];
473
- cycleDetected: boolean;
474
- maxDepthReached: boolean;
475
- }>;
476
- /**
477
- * Require membership on a group, checking inherited membership
478
- * from ancestor groups when no direct membership exists.
479
- *
480
- * Throws `FORBIDDEN` if no matching membership is found.
481
- */
482
- require: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
483
- userId: string;
484
- groupId: string;
485
- roles?: string[];
486
- maxDepth?: number;
487
- }) => Promise<{
488
- membership: any;
489
- matchedGroupId: string | null;
490
- isDirect: boolean;
491
- isInherited: boolean;
492
- depth: number | null;
493
- }>;
494
- };
495
- /**
496
- * Manage platform-level invitations.
497
- *
498
- * Invites can optionally target a group by setting `groupId`, but they do
499
- * not require groups and can be used in apps with user-only collaboration.
500
- */
501
- invite: {
502
- /**
503
- * Create a new invitation.
504
- *
505
- * @param data.groupId - Optional group to invite the user into.
506
- * @param data.invitedByUserId - Optional user sending the invitation
507
- * (omit for CLI-generated invites).
508
- * @param data.email - Optional email of the invitee (omit for
509
- * CLI-generated invite links where the email is unknown upfront).
510
- * @param data.role - Optional role to assign on acceptance.
511
- * @param data.expiresTime - Optional expiration timestamp (omit for
512
- * single-use, non-expiring invites).
513
- * @param data.extend - Optional arbitrary JSON extension data.
514
- * @throws ConvexError with code `DUPLICATE_INVITE` if a pending invite
515
- * already exists for this email and scope.
516
- * @returns An object with `inviteId` and raw `token`.
517
- */
518
- create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
519
- groupId?: string;
520
- invitedByUserId?: string;
521
- email?: string;
522
- role?: string;
523
- expiresTime?: number;
524
- extend?: Record<string, unknown>;
525
- }) => Promise<{
526
- inviteId: string;
527
- token: string;
528
- }>;
529
- /**
530
- * Retrieve an invite by its ID. Returns `null` if not found.
531
- */
532
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, inviteId: string) => Promise<any>;
533
- /**
534
- * Token-based invite helpers.
535
- */
536
- token: {
537
- /**
538
- * Retrieve an invite by raw token.
539
- */
540
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, token: string) => Promise<any>;
541
- /**
542
- * Accept an invitation by raw token and atomically add group membership
543
- * when the invite is group-scoped.
544
- */
545
- accept: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, args: {
546
- token: string;
547
- acceptedByUserId: string;
548
- }) => Promise<any>;
549
- };
550
- /**
551
- * List invites with optional filtering, sorting, and pagination.
552
- *
553
- * ```ts
554
- * // Pending invites for a group
555
- * await auth.invite.list(ctx, { where: { groupId, status: "pending" } });
556
- * ```
557
- */
558
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
559
- where?: {
560
- tokenHash?: string;
561
- groupId?: string;
562
- status?: "pending" | "accepted" | "revoked" | "expired";
563
- email?: string;
564
- invitedByUserId?: string;
565
- role?: string;
566
- acceptedByUserId?: string;
567
- };
568
- limit?: number;
569
- cursor?: string | null;
570
- orderBy?: "_creationTime" | "status" | "email" | "expiresTime" | "acceptedTime";
571
- order?: "asc" | "desc";
572
- }) => Promise<any>;
573
- /**
574
- * Accept an invitation. Marks the invite as "accepted" and records
575
- * the timestamp. If the invite has a group, the caller is responsible
576
- * for creating the member record via `auth.member.add` in the
577
- * same Convex mutation for transactional safety.
578
- *
579
- * @param ctx - Convex context with `runMutation`.
580
- * @param inviteId - The invite document ID.
581
- * @param acceptedByUserId - User accepting the invite (recorded for audit).
582
- * @throws `ConvexError` with code `INVITE_NOT_FOUND` when the invite does not exist.
583
- * @throws `ConvexError` with code `INVITE_NOT_PENDING` when the invite is not in `pending` status.
584
- *
585
- * @example
586
- * ```ts
587
- * export const acceptInvite = mutation({
588
- * args: { inviteId: v.string() },
589
- * handler: async (ctx, { inviteId }) => {
590
- * const userId = await auth.user.require(ctx);
591
- * const invite = await auth.invite.get(ctx, inviteId);
592
- * if (!invite) throw new Error("Invite not found");
593
- *
594
- * await auth.invite.accept(ctx, inviteId);
595
- * if (invite.groupId) {
596
- * await auth.member.add(ctx, {
597
- * groupId: invite.groupId,
598
- * userId,
599
- * role: invite.role,
600
- * });
601
- * }
602
- * },
603
- * });
604
- * ```
605
- */
606
- accept: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, inviteId: string, acceptedByUserId?: string) => Promise<void>;
607
- /**
608
- * Revoke a pending invitation.
609
- *
610
- * @param ctx - Convex context with `runMutation`.
611
- * @param inviteId - The invite document ID.
612
- * @throws `ConvexError` with code `INVITE_NOT_FOUND` when the invite does not exist.
613
- * @throws `ConvexError` with code `INVITE_NOT_PENDING` when the invite is not in `pending` status.
614
- */
615
- revoke: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, inviteId: string) => Promise<void>;
616
- };
617
- /**
618
- * Manage passkey credentials for users.
619
- *
620
- * ```ts
621
- * const passkeys = await auth.passkey.list(ctx, { userId });
622
- * await auth.passkey.rename(ctx, passkeyId, "MacBook Touch ID");
623
- /**
624
- * Manage API keys for programmatic access.
625
- *
626
- * Keys use SHA-256 hashing (via `@oslojs/crypto`) and support
627
- * scoped resource:action permissions with optional per-key rate limiting.
628
- *
629
- * ```ts
630
- * const { keyId, raw } = await auth.key.create(ctx, {
631
- * userId,
632
- * name: "CI Pipeline",
633
- * scopes: [{ resource: "data", actions: ["read"] }],
634
- * });
635
- * // raw = "sk_abc123..." — show once, never stored
636
- *
637
- * const result = await auth.key.verify(ctx, rawKey);
638
- * result.scopes.can("data", "read"); // true
639
- * ```
640
- */
641
- key: {
642
- /**
643
- * Create a new API key. Returns the raw key **once** — it cannot
644
- * be retrieved again after creation.
645
- *
646
- * @param opts.userId - The user this key belongs to.
647
- * @param opts.name - Human-readable name (e.g. "CI Pipeline").
648
- * @param opts.scopes - Resource:action permissions for this key.
649
- * @param opts.rateLimit - Optional per-key rate limit override.
650
- * @param opts.expiresAt - Optional expiration timestamp.
651
- * @param opts.metadata - Optional arbitrary app data attached to the key.
652
- * @returns `{ keyId, raw }` where `raw` is the full key string.
653
- */
654
- create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, opts: {
655
- userId: string;
656
- name: string;
657
- scopes: KeyScope[];
658
- rateLimit?: {
659
- maxRequests: number;
660
- windowMs: number;
661
- };
662
- expiresAt?: number;
663
- metadata?: Record<string, unknown>;
664
- }) => Promise<{
665
- keyId: string;
666
- raw: string;
667
- }>;
668
- /**
669
- * Verify a raw API key string. Returns the userId and a scope checker
670
- * if the key is valid, not revoked, not expired, and not rate-limited.
671
- *
672
- * Also updates `lastUsedAt` and rate limit state as a side effect.
673
- *
674
- * @throws Error if the key is invalid, revoked, expired, or rate-limited.
675
- */
676
- verify: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, rawKey: string) => Promise<{
677
- userId: string;
678
- keyId: string;
679
- scopes: ScopeChecker;
680
- }>;
681
- /**
682
- * List API keys with optional filtering, sorting, and pagination.
683
- * Never includes the raw key — only the display prefix.
684
- *
685
- * ```ts
686
- * // All keys for a user
687
- * await auth.key.list(ctx, { where: { userId } });
688
- *
689
- * // Only active (non-revoked)
690
- * await auth.key.list(ctx, { where: { userId, revoked: false } });
691
- * ```
692
- */
693
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
694
- where?: {
695
- userId?: string;
696
- revoked?: boolean;
697
- name?: string;
698
- prefix?: string;
699
- };
700
- limit?: number;
701
- cursor?: string | null;
702
- orderBy?: "_creationTime" | "name" | "lastUsedAt" | "expiresAt" | "revoked";
703
- order?: "asc" | "desc";
704
- }) => Promise<any>;
705
- /**
706
- * Get a single API key by its document ID.
707
- * Returns `null` if not found.
708
- */
709
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, keyId: string) => Promise<KeyDoc | null>;
710
- /**
711
- * Update an API key's metadata (name, scopes, rate limit).
712
- */
713
- update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, keyId: string, data: {
714
- name?: string;
715
- scopes?: KeyScope[];
716
- rateLimit?: {
717
- maxRequests: number;
718
- windowMs: number;
719
- };
720
- }) => Promise<void>;
721
- /**
722
- * Revoke an API key (soft delete). The key record is preserved
723
- * for audit purposes but can no longer be used for authentication.
724
- */
725
- revoke: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, keyId: string) => Promise<void>;
726
- /**
727
- * Hard delete an API key record.
728
- */
729
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, keyId: string) => Promise<void>;
730
- /**
731
- * Rotate an API key — revoke the old key and issue a replacement with
732
- * the same `userId`, `name`, `scopes`, and `rateLimit`.
733
- *
734
- * The old key is soft-revoked immediately; the replacement is a brand
735
- * new key with a new raw value. Returns the new `keyId` and `raw` key
736
- * (shown once, same as `auth.key.create`).
737
- *
738
- * @throws If the key does not exist or is already revoked.
739
- *
740
- * @example
741
- * ```ts
742
- * const { keyId, raw } = await auth.key.rotate(ctx, oldKeyId);
743
- * // raw = "sk_abc..." — new key to hand to the caller
744
- * // old key is now revoked and verify() will throw API_KEY_REVOKED
745
- * ```
746
- */
747
- rotate: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, keyId: string, opts?: {
748
- name?: string;
749
- expiresAt?: number;
750
- }) => Promise<{
751
- keyId: string;
752
- raw: string;
753
- }>;
754
- };
755
- /**
756
- * SSO namespace — enterprise SSO connection management, domain, OIDC,
757
- * SAML, SCIM, audit, and webhook helpers.
758
- */
759
- sso: {
760
- connection: {
761
- create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
762
- groupId: string;
763
- slug?: string;
764
- name?: string;
765
- status?: "draft" | "active" | "disabled";
766
- config?: Record<string, unknown>;
767
- extend?: Record<string, unknown>;
768
- }) => Promise<string>;
769
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<any>;
770
- getByGroup: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, groupId: string) => Promise<any>;
771
- getByDomain: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, domain: string) => Promise<any>;
772
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
773
- where?: {
774
- groupId?: string;
775
- slug?: string;
776
- status?: "draft" | "active" | "disabled";
777
- };
778
- limit?: number;
779
- cursor?: string | null;
780
- orderBy?: "_creationTime" | "name" | "slug" | "status";
781
- order?: "asc" | "desc";
782
- }) => Promise<any>;
783
- update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, enterpriseId: string, data: Record<string, unknown>) => Promise<void>;
784
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, enterpriseId: string) => Promise<void>;
785
- /**
786
- * Aggregate readiness status across all configured protocols for an
787
- * enterprise connection.
788
- *
789
- * Returns a structured result indicating whether the connection is
790
- * ready, with per-protocol checks so callers can surface actionable
791
- * diagnostics without running full network validation.
792
- */
793
- status: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<{
794
- enterpriseId: any;
795
- status: any;
796
- ready: boolean;
797
- domainCount: number;
798
- protocols: {
799
- oidc: {
800
- configured: boolean;
801
- ready: boolean;
802
- clientId: any;
803
- issuer: any;
804
- };
805
- saml: {
806
- configured: boolean;
807
- ready: boolean;
808
- entityId: any;
809
- };
810
- scim: {
811
- configured: boolean;
812
- ready: boolean;
813
- basePath: any;
814
- deprovisionMode: any;
815
- };
816
- };
817
- }>;
818
- };
819
- domain: {
820
- add: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
821
- enterpriseId: string;
822
- groupId: string;
823
- domain: string;
824
- isPrimary?: boolean;
825
- verifiedAt?: number;
826
- }) => Promise<string>;
827
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<any>;
828
- remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, domainId: string) => Promise<void>;
829
- };
830
- saml: {
831
- configure: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, data: {
832
- enterpriseId: string;
833
- metadataXml?: string;
834
- metadataUrl?: string;
835
- domains?: string[];
836
- signAuthnRequests?: boolean;
837
- attributeMapping?: {
838
- subject?: string;
839
- email?: string;
840
- name?: string;
841
- firstName?: string;
842
- lastName?: string;
843
- };
844
- sp?: {
845
- entityId?: string;
846
- acsUrl?: string;
847
- sloUrl?: string;
848
- signingCert?: string | string[];
849
- encryptCert?: string | string[];
850
- privateKey?: string;
851
- privateKeyPass?: string;
852
- encPrivateKey?: string;
853
- encPrivateKeyPass?: string;
854
- };
855
- }) => Promise<{
856
- enterpriseId: any;
857
- groupId: any;
858
- }>;
859
- metadata: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, opts: {
860
- enterpriseId: string;
861
- entityId?: string;
862
- acsUrl?: string;
863
- sloUrl?: string;
864
- }) => Promise<any>;
865
- /**
866
- * Validate the stored SAML config for an enterprise connection.
867
- *
868
- * Re-parses IdP metadata, checks signing cert presence, and verifies
869
- * SP metadata can be generated. Returns a structured result with
870
- * per-check details rather than throwing on first failure.
871
- */
872
- validate: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, enterpriseId: string) => Promise<{
873
- ok: boolean;
874
- enterpriseId: any;
875
- checks: {
876
- name: string;
877
- ok: boolean;
878
- message?: string;
879
- }[];
880
- }>;
881
- };
882
- oidc: {
883
- /**
884
- * Register or update enterprise OIDC connection settings.
885
- *
886
- * Persists protocol config under `enterprise.config.protocols.oidc` and
887
- * records an `enterprise.oidc.registered` audit event.
888
- */
889
- configure: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
890
- enterpriseId: string;
891
- issuer?: string;
892
- discoveryUrl?: string;
893
- clientId: string;
894
- clientSecret?: string;
895
- scopes?: string[];
896
- authorizationParams?: Record<string, string>;
897
- clockToleranceSeconds?: number;
898
- strictIssuer?: boolean;
899
- /**
900
- * Map OIDC claim names to `user.extend` field names.
901
- * Example: `{ department: "department", role: "job_title" }` means
902
- * the OIDC `department` claim is stored as `user.extend.department`.
903
- */
904
- extraFields?: Record<string, string>;
905
- }) => Promise<Record<string, any>>;
906
- /**
907
- * Fetch the stored OIDC config for an enterprise.
908
- */
909
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<Record<string, any>>;
910
- /**
911
- * Resolve enterprise OIDC sign-in route from enterprise id, domain, or
912
- * user email domain.
913
- */
914
- resolveSignIn: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, data: {
915
- enterpriseId?: string;
916
- email?: string;
917
- domain?: string;
918
- redirectTo?: string;
919
- }) => Promise<{
920
- enterpriseId: any;
921
- providerId: string;
922
- signInPath: string;
923
- callbackPath: string;
924
- redirectTo: string | undefined;
925
- }>;
926
- /**
927
- * Validate the stored OIDC config for an enterprise connection.
928
- *
929
- * Fetches the OIDC discovery document from the configured issuer or
930
- * discoveryUrl, verifies required fields are present, and checks that
931
- * clientId is set. Returns a structured result with per-check details.
932
- */
933
- validate: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<{
934
- ok: boolean;
935
- enterpriseId: any;
936
- checks: {
937
- name: string;
938
- ok: boolean;
939
- message?: string;
940
- }[];
941
- }>;
942
- };
943
- scim: {
944
- configure: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
945
- enterpriseId: string;
946
- basePath?: string;
947
- deprovisionMode?: "soft" | "hard";
948
- status?: "draft" | "active" | "disabled";
949
- }) => Promise<{
950
- token: string;
951
- configId: string;
952
- }>;
953
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<any>;
954
- getConfigByToken: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, token: string) => Promise<any>;
955
- /**
956
- * Validate the stored SCIM config for an enterprise connection.
957
- *
958
- * Checks that a SCIM config record exists, is active, has a token
959
- * hash set, and has a non-empty basePath. Returns a structured result
960
- * with per-check details.
961
- */
962
- validate: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<{
963
- ok: boolean;
964
- enterpriseId: string;
965
- checks: {
966
- name: string;
967
- ok: boolean;
968
- message: string;
969
- }[];
970
- basePath?: undefined;
971
- deprovisionMode?: undefined;
972
- } | {
973
- ok: boolean;
974
- enterpriseId: any;
975
- basePath: any;
976
- deprovisionMode: any;
977
- checks: {
978
- name: string;
979
- ok: boolean;
980
- message?: string;
981
- }[];
982
- }>;
983
- identity: {
984
- get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, data: {
985
- enterpriseId: string;
986
- resourceType: "user" | "group";
987
- externalId: string;
988
- }) => Promise<any>;
989
- upsert: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
990
- enterpriseId: string;
991
- groupId: string;
992
- resourceType: "user" | "group";
993
- externalId: string;
994
- userId?: string;
995
- mappedGroupId?: string;
996
- active?: boolean;
997
- raw?: Record<string, unknown>;
998
- }) => Promise<string>;
999
- };
1000
- };
1001
- audit: {
1002
- record: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
1003
- enterpriseId: string;
1004
- groupId: string;
1005
- eventType: string;
1006
- actorType: "user" | "system" | "scim" | "api_key" | "webhook";
1007
- actorId?: string;
1008
- subjectType: string;
1009
- subjectId?: string;
1010
- ok: boolean;
1011
- requestId?: string;
1012
- ip?: string;
1013
- metadata?: Record<string, unknown>;
1014
- }) => Promise<string>;
1015
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, data: {
1016
- enterpriseId?: string;
1017
- groupId?: string;
1018
- limit?: number;
1019
- }) => Promise<any>;
1020
- };
1021
- webhook: {
1022
- endpoint: {
1023
- create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
1024
- enterpriseId: string;
1025
- url: string;
1026
- secret: string;
1027
- subscriptions: string[];
1028
- createdByUserId?: string;
1029
- }) => Promise<{
1030
- endpointId: string;
1031
- }>;
1032
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, enterpriseId: string) => Promise<any>;
1033
- disable: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, endpointId: string) => Promise<void>;
1034
- };
1035
- emit: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
1036
- enterpriseId: string;
1037
- eventType: string;
1038
- payload: Record<string, unknown>;
1039
- auditEventId?: string;
1040
- }) => Promise<void>;
1041
- delivery: {
1042
- list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, data: {
1043
- enterpriseId: string;
1044
- limit?: number;
1045
- }) => Promise<any>;
1046
- listReady: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, limit?: number) => Promise<any>;
1047
- markDelivered: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, deliveryId: string, responseStatus?: number) => Promise<void>;
1048
- markFailed: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, deliveryId: string, data: {
1049
- attemptCount: number;
1050
- responseStatus?: number;
1051
- error?: string;
1052
- retryAt?: number;
1053
- }) => Promise<void>;
1054
- };
1055
- };
1056
- };
1057
- /**
1058
- * HTTP namespace — route registration and Bearer-authenticated endpoints.
1059
- */
1060
- http: {
1061
- /**
1062
- * Register core HTTP routes for JWT verification and OAuth sign-in.
1063
- *
1064
- * ```ts
1065
- * import { httpRouter } from "convex/server";
1066
- * import { auth } from "./auth";
1067
- *
1068
- * const http = httpRouter();
1069
- *
1070
- * auth.http.add(http);
1071
- *
1072
- * export default http;
1073
- * ```
1074
- *
1075
- * The following routes are handled always:
1076
- *
1077
- * - `/.well-known/openid-configuration`
1078
- * - `/.well-known/jwks.json`
1079
- *
1080
- * The following routes are handled if OAuth is configured:
1081
- *
1082
- * - `/api/auth/signin/*`
1083
- * - `/api/auth/callback/*`
1084
- *
1085
- * @param http your HTTP router
1086
- */
1087
- add: (http: HttpRouter) => void;
1088
- /**
1089
- * Wrap an HTTP action handler with Bearer token authentication.
1090
- *
1091
- * Extracts the `Authorization: Bearer <key>` header, verifies the
1092
- * API key via `auth.key.verify()`, and injects `ctx.key` with the
1093
- * verified key info. Returns structured JSON error responses for
1094
- * missing/invalid/revoked/expired/rate-limited keys.
1095
- *
1096
- * If the handler returns a plain object, it is auto-wrapped in a
1097
- * `200 JSON` response. If it returns a `Response`, CORS headers
1098
- * are merged and the response is passed through.
1099
- *
1100
- * ```ts
1101
- * const handler = auth.http.action(async (ctx, request) => {
1102
- * const data = await ctx.runQuery(api.data.get, { userId: ctx.key.userId });
1103
- * return { data };
1104
- * });
1105
- * http.route({ path: "/api/data", method: "GET", handler });
1106
- * ```
1107
- *
1108
- * @param handler - Receives enriched `ctx` (with `ctx.key`) and the raw `Request`.
1109
- * @param options.scope - Optional scope check; returns 403 if the key lacks permission.
1110
- * @param options.cors - CORS config; defaults to permissive (`*`).
1111
- */
1112
- action: (handler: (ctx: GenericActionCtx<GenericDataModel> & HttpKeyContext, request: Request) => Promise<Response | Record<string, unknown>>, options?: {
1113
- scope?: {
1114
- resource: string;
1115
- action: string;
1116
- };
1117
- cors?: CorsConfig;
1118
- }) => convex_server23.PublicHttpAction;
1119
- /**
1120
- * Register a Bearer-authenticated route **and** its OPTIONS preflight
1121
- * in a single call.
1122
- *
1123
- * ```ts
1124
- * auth.http.route(http, {
1125
- * path: "/api/messages",
1126
- * method: "POST",
1127
- * handler: async (ctx, request) => {
1128
- * const { body } = await request.json();
1129
- * await ctx.runMutation(internal.messages.sendAsUser, {
1130
- * userId: ctx.key.userId,
1131
- * body,
1132
- * });
1133
- * return { success: true };
1134
- * },
1135
- * });
1136
- * ```
1137
- *
1138
- * @param http - The Convex HTTP router.
1139
- * @param routeConfig.path - The URL path to match.
1140
- * @param routeConfig.method - HTTP method (GET, POST, PUT, PATCH, DELETE).
1141
- * @param routeConfig.handler - Receives enriched `ctx` (with `ctx.key`) and the raw `Request`.
1142
- * @param routeConfig.scope - Optional scope check; returns 403 if the key lacks permission.
1143
- * @param routeConfig.cors - CORS config; defaults to permissive (`*`).
1144
- */
1145
- route: (http: HttpRouter, routeConfig: {
1146
- path: string;
1147
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
1148
- handler: (ctx: GenericActionCtx<GenericDataModel> & HttpKeyContext, request: Request) => Promise<Response | Record<string, unknown>>;
1149
- scope?: {
1150
- resource: string;
1151
- action: string;
1152
- };
1153
- cors?: CorsConfig;
1154
- }) => void;
1155
- };
1156
- };
1157
- /**
1158
- * Action called by the client to sign the user in.
1159
- *
1160
- * Also used for refreshing the session.
1161
- */
1162
- signIn: convex_server23.RegisteredAction<"public", {
1163
- provider?: string | undefined;
1164
- verifier?: string | undefined;
1165
- params?: any;
1166
- refreshToken?: string | undefined;
1167
- calledBy?: string | undefined;
1168
- }, Promise<SignInActionResult>>;
1169
- /**
1170
- * Action called by the client to invalidate the current session.
1171
- */
1172
- signOut: convex_server23.RegisteredAction<"public", {}, Promise<void>>;
1173
- /**
1174
- * Internal mutation used by the library to read and write
1175
- * to the database during signin and signout.
1176
- */
1177
- store: convex_server23.RegisteredMutation<"internal", {
1178
- args: {
1179
- sessionId?: string | undefined;
1180
- type: "signIn";
1181
- userId: string;
1182
- generateTokens: boolean;
1183
- } | {
1184
- type: "signOut";
1185
- } | {
1186
- type: "refreshSession";
1187
- refreshToken: string;
1188
- } | {
1189
- provider?: string | undefined;
1190
- verifier?: string | undefined;
1191
- type: "verifyCodeAndSignIn";
1192
- params: any;
1193
- generateTokens: boolean;
1194
- allowExtraProviders: boolean;
1195
- } | {
1196
- type: "verifier";
1197
- } | {
1198
- type: "verifierSignature";
1199
- verifier: string;
1200
- signature: string;
1201
- } | {
1202
- accountExtend?: any;
1203
- type: "userOAuth";
1204
- provider: string;
1205
- providerAccountId: string;
1206
- signature: string;
1207
- profile: any;
1208
- } | {
1209
- email?: string | undefined;
1210
- phone?: string | undefined;
1211
- accountId?: string | undefined;
1212
- type: "createVerificationCode";
1213
- expirationTime: number;
1214
- provider: string;
1215
- code: string;
1216
- allowExtraProviders: boolean;
1217
- } | {
1218
- shouldLinkViaEmail?: boolean | undefined;
1219
- shouldLinkViaPhone?: boolean | undefined;
1220
- type: "createAccountFromCredentials";
1221
- provider: string;
1222
- profile: any;
1223
- account: {
1224
- secret?: string | undefined;
1225
- id: string;
1226
- };
1227
- } | {
1228
- type: "retrieveAccountWithCredentials";
1229
- provider: string;
1230
- account: {
1231
- secret?: string | undefined;
1232
- id: string;
1233
- };
1234
- } | {
1235
- type: "modifyAccount";
1236
- provider: string;
1237
- account: {
1238
- id: string;
1239
- secret: string;
1240
- };
1241
- } | {
1242
- except?: string[] | undefined;
1243
- type: "invalidateSessions";
1244
- userId: string;
1245
- };
1246
- }, Promise<string | void | {
1247
- userId: GenericId<"User">;
1248
- sessionId: GenericId<"Session">;
1249
- } | (string & {
1250
- __tableName: "AuthVerifier";
1251
- }) | SessionInfo | {
1252
- token: string;
1253
- refreshToken: string;
1254
- } | {
1255
- account: Doc<"Account">;
1256
- user: Doc<"User">;
1257
- } | {
1258
- account: Doc<"Account">;
1259
- user: Doc<"User">;
1260
- } | null>>;
1261
- };
1262
- //#endregion
1263
- export { Auth };
1264
- //# sourceMappingURL=implementation.d.ts.map