@robelest/convex-auth 0.0.4-preview.2 → 0.0.4-preview.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -26
- package/dist/authorization/index.d.ts +63 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +63 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/bin.js +6185 -0
- package/dist/client/core/types.d.ts +20 -0
- package/dist/client/core/types.d.ts.map +1 -0
- package/dist/client/index.d.ts +2 -299
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +407 -534
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +42 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +2546 -90
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/client/core/types.d.ts +2 -0
- package/dist/component/client/index.d.ts +2 -0
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/functions.d.ts +11 -9
- package/dist/component/functions.d.ts.map +1 -1
- package/dist/component/functions.js.map +1 -1
- package/dist/component/index.d.ts +7 -11
- package/dist/component/index.js +2 -3
- package/dist/component/model.d.ts +153 -0
- package/dist/component/model.d.ts.map +1 -0
- package/dist/component/model.js +349 -0
- package/dist/component/model.js.map +1 -0
- package/dist/component/providers/anonymous.d.ts +54 -0
- package/dist/component/providers/anonymous.d.ts.map +1 -0
- package/dist/component/providers/credentials.d.ts +5 -5
- package/dist/component/providers/credentials.d.ts.map +1 -1
- package/dist/component/providers/device.d.ts +67 -0
- package/dist/component/providers/device.d.ts.map +1 -0
- package/dist/component/providers/email.d.ts +62 -0
- package/dist/component/providers/email.d.ts.map +1 -0
- package/dist/component/providers/oauth.d.ts.map +1 -1
- package/dist/component/providers/oauth.js.map +1 -1
- package/dist/component/providers/passkey.d.ts +57 -0
- package/dist/component/providers/passkey.d.ts.map +1 -0
- package/dist/component/providers/password.d.ts +88 -0
- package/dist/component/providers/password.d.ts.map +1 -0
- package/dist/component/providers/phone.d.ts +48 -0
- package/dist/component/providers/phone.d.ts.map +1 -0
- package/dist/component/providers/sso.d.ts +50 -0
- package/dist/component/providers/sso.d.ts.map +1 -0
- package/dist/component/providers/totp.d.ts +45 -0
- package/dist/component/providers/totp.d.ts.map +1 -0
- package/dist/component/public/enterprise/audit.d.ts +73 -0
- package/dist/component/public/enterprise/audit.d.ts.map +1 -0
- package/dist/component/public/enterprise/audit.js +108 -0
- package/dist/component/public/enterprise/audit.js.map +1 -0
- package/dist/component/public/enterprise/core.d.ts +176 -0
- package/dist/component/public/enterprise/core.d.ts.map +1 -0
- package/dist/component/public/enterprise/core.js +292 -0
- package/dist/component/public/enterprise/core.js.map +1 -0
- package/dist/component/public/enterprise/domains.d.ts +174 -0
- package/dist/component/public/enterprise/domains.d.ts.map +1 -0
- package/dist/component/public/enterprise/domains.js +271 -0
- package/dist/component/public/enterprise/domains.js.map +1 -0
- package/dist/component/public/enterprise/scim.d.ts +245 -0
- package/dist/component/public/enterprise/scim.d.ts.map +1 -0
- package/dist/component/public/enterprise/scim.js +344 -0
- package/dist/component/public/enterprise/scim.js.map +1 -0
- package/dist/component/public/enterprise/secrets.d.ts +78 -0
- package/dist/component/public/enterprise/secrets.d.ts.map +1 -0
- package/dist/component/public/enterprise/secrets.js +118 -0
- package/dist/component/public/enterprise/secrets.js.map +1 -0
- package/dist/component/public/enterprise/webhooks.d.ts +211 -0
- package/dist/component/public/enterprise/webhooks.d.ts.map +1 -0
- package/dist/component/public/enterprise/webhooks.js +300 -0
- package/dist/component/public/enterprise/webhooks.js.map +1 -0
- package/dist/component/public/factors/devices.d.ts +157 -0
- package/dist/component/public/factors/devices.d.ts.map +1 -0
- package/dist/component/public/factors/devices.js +216 -0
- package/dist/component/public/factors/devices.js.map +1 -0
- package/dist/component/public/factors/passkeys.d.ts +175 -0
- package/dist/component/public/factors/passkeys.d.ts.map +1 -0
- package/dist/component/public/factors/passkeys.js +238 -0
- package/dist/component/public/factors/passkeys.js.map +1 -0
- package/dist/component/public/factors/totp.d.ts +189 -0
- package/dist/component/public/factors/totp.d.ts.map +1 -0
- package/dist/component/public/factors/totp.js +254 -0
- package/dist/component/public/factors/totp.js.map +1 -0
- package/dist/component/public/groups/core.d.ts +137 -0
- package/dist/component/public/groups/core.d.ts.map +1 -0
- package/dist/component/public/groups/core.js +321 -0
- package/dist/component/public/groups/core.js.map +1 -0
- package/dist/component/public/groups/invites.d.ts +217 -0
- package/dist/component/public/groups/invites.d.ts.map +1 -0
- package/dist/component/public/groups/invites.js +457 -0
- package/dist/component/public/groups/invites.js.map +1 -0
- package/dist/component/public/groups/members.d.ts +204 -0
- package/dist/component/public/groups/members.d.ts.map +1 -0
- package/dist/component/public/groups/members.js +355 -0
- package/dist/component/public/groups/members.js.map +1 -0
- package/dist/component/public/identity/accounts.d.ts +147 -0
- package/dist/component/public/identity/accounts.d.ts.map +1 -0
- package/dist/component/public/identity/accounts.js +200 -0
- package/dist/component/public/identity/accounts.js.map +1 -0
- package/dist/component/public/identity/codes.d.ts +104 -0
- package/dist/component/public/identity/codes.d.ts.map +1 -0
- package/dist/component/public/identity/codes.js +140 -0
- package/dist/component/public/identity/codes.js.map +1 -0
- package/dist/component/public/identity/sessions.d.ts +128 -0
- package/dist/component/public/identity/sessions.d.ts.map +1 -0
- package/dist/component/public/identity/sessions.js +192 -0
- package/dist/component/public/identity/sessions.js.map +1 -0
- package/dist/component/public/identity/tokens.d.ts +169 -0
- package/dist/component/public/identity/tokens.d.ts.map +1 -0
- package/dist/component/public/identity/tokens.js +227 -0
- package/dist/component/public/identity/tokens.js.map +1 -0
- package/dist/component/public/identity/users.d.ts +212 -0
- package/dist/component/public/identity/users.d.ts.map +1 -0
- package/dist/component/public/identity/users.js +311 -0
- package/dist/component/public/identity/users.js.map +1 -0
- package/dist/component/public/identity/verifiers.d.ts +116 -0
- package/dist/component/public/identity/verifiers.d.ts.map +1 -0
- package/dist/component/public/identity/verifiers.js +154 -0
- package/dist/component/public/identity/verifiers.js.map +1 -0
- package/dist/component/public/security/keys.d.ts +209 -0
- package/dist/component/public/security/keys.d.ts.map +1 -0
- package/dist/component/public/security/keys.js +319 -0
- package/dist/component/public/security/keys.js.map +1 -0
- package/dist/component/public/security/limits.d.ts +114 -0
- package/dist/component/public/security/limits.d.ts.map +1 -0
- package/dist/component/public/security/limits.js +169 -0
- package/dist/component/public/security/limits.js.map +1 -0
- package/dist/component/public.d.ts +24 -271
- package/dist/component/public.d.ts.map +1 -1
- package/dist/component/public.js +21 -1229
- package/dist/component/schema.d.ts +473 -110
- package/dist/component/schema.js +162 -73
- package/dist/component/schema.js.map +1 -1
- package/dist/component/server/auth.d.ts +318 -373
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +204 -123
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/authError.js +34 -0
- package/dist/component/server/authError.js.map +1 -0
- package/dist/component/server/{providers.js → config.js} +43 -12
- package/dist/component/server/config.js.map +1 -0
- package/dist/component/server/cookies.js +3 -0
- package/dist/component/server/cookies.js.map +1 -1
- package/dist/component/server/core.js +713 -0
- package/dist/component/server/core.js.map +1 -0
- package/dist/component/server/crypto.js +38 -0
- package/dist/component/server/crypto.js.map +1 -0
- package/dist/component/server/{implementation/db.js → db.js} +2 -1
- package/dist/component/server/db.js.map +1 -0
- package/dist/component/server/device.js +109 -0
- package/dist/component/server/device.js.map +1 -0
- package/dist/component/server/enterprise/config.js +46 -0
- package/dist/component/server/enterprise/config.js.map +1 -0
- package/dist/component/server/enterprise/domain.js +885 -0
- package/dist/component/server/enterprise/domain.js.map +1 -0
- package/dist/component/server/enterprise/http.js +766 -0
- package/dist/component/server/enterprise/http.js.map +1 -0
- package/dist/component/server/enterprise/oidc.js +248 -0
- package/dist/component/server/enterprise/oidc.js.map +1 -0
- package/dist/component/server/enterprise/policy.js +85 -0
- package/dist/component/server/enterprise/policy.js.map +1 -0
- package/dist/component/server/enterprise/saml.js +338 -0
- package/dist/component/server/enterprise/saml.js.map +1 -0
- package/dist/component/server/enterprise/scim.js +97 -0
- package/dist/component/server/enterprise/scim.js.map +1 -0
- package/dist/component/server/enterprise/shared.js +51 -0
- package/dist/component/server/enterprise/shared.js.map +1 -0
- package/dist/component/server/errors.d.ts +1 -0
- package/dist/component/server/errors.js +24 -16
- package/dist/component/server/errors.js.map +1 -1
- package/dist/component/server/http.js +288 -0
- package/dist/component/server/http.js.map +1 -0
- package/dist/component/server/identity.js +13 -0
- package/dist/component/server/identity.js.map +1 -0
- package/dist/{server/implementation → component/server}/keys.js +9 -31
- package/dist/component/server/keys.js.map +1 -0
- package/dist/component/server/limits.js +61 -0
- package/dist/component/server/limits.js.map +1 -0
- package/dist/component/server/mutations/account.js +44 -0
- package/dist/component/server/mutations/account.js.map +1 -0
- package/dist/component/server/{implementation/mutations → mutations}/code.js +7 -4
- package/dist/component/server/mutations/code.js.map +1 -0
- package/dist/component/server/mutations/invalidate.js +32 -0
- package/dist/component/server/mutations/invalidate.js.map +1 -0
- package/dist/component/server/mutations/oauth.js +110 -0
- package/dist/component/server/mutations/oauth.js.map +1 -0
- package/dist/component/server/mutations/refresh.js +119 -0
- package/dist/component/server/mutations/refresh.js.map +1 -0
- package/dist/component/server/mutations/register.js +83 -0
- package/dist/component/server/mutations/register.js.map +1 -0
- package/dist/component/server/mutations/retrieve.js +65 -0
- package/dist/component/server/mutations/retrieve.js.map +1 -0
- package/dist/component/server/mutations/signature.js +32 -0
- package/dist/component/server/mutations/signature.js.map +1 -0
- package/dist/component/server/{implementation/mutations → mutations}/signin.js +2 -2
- package/dist/component/server/mutations/signin.js.map +1 -0
- package/dist/component/server/mutations/signout.js +27 -0
- package/dist/component/server/mutations/signout.js.map +1 -0
- package/dist/component/server/mutations/store/refs.js +15 -0
- package/dist/component/server/mutations/store/refs.js.map +1 -0
- package/dist/component/server/mutations/store.js +85 -0
- package/dist/component/server/mutations/store.js.map +1 -0
- package/dist/component/server/mutations/verifier.js +18 -0
- package/dist/component/server/mutations/verifier.js.map +1 -0
- package/dist/component/server/mutations/verify.js +98 -0
- package/dist/component/server/mutations/verify.js.map +1 -0
- package/dist/component/server/oauth.js +106 -60
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +328 -0
- package/dist/component/server/passkey.js.map +1 -0
- package/dist/{server/implementation → component/server}/redirects.js +13 -11
- package/dist/component/server/redirects.js.map +1 -0
- package/dist/component/server/refresh.js +96 -0
- package/dist/component/server/refresh.js.map +1 -0
- package/dist/component/server/runtime.d.ts +136 -0
- package/dist/component/server/runtime.d.ts.map +1 -0
- package/dist/component/server/runtime.js +413 -0
- package/dist/component/server/runtime.js.map +1 -0
- package/dist/{server/implementation → component/server}/sessions.js +14 -8
- package/dist/component/server/sessions.js.map +1 -0
- package/dist/component/server/signin.js +201 -0
- package/dist/component/server/signin.js.map +1 -0
- package/dist/component/server/tokens.js +17 -0
- package/dist/component/server/tokens.js.map +1 -0
- package/dist/component/server/totp.js +148 -0
- package/dist/component/server/totp.js.map +1 -0
- package/dist/component/server/types.d.ts +387 -298
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/component/server/{implementation/types.js → types.js} +1 -1
- package/dist/component/server/types.js.map +1 -0
- package/dist/component/server/{implementation/users.js → users.js} +54 -35
- package/dist/component/server/users.js.map +1 -0
- package/dist/component/server/utils.js +110 -4
- package/dist/component/server/utils.js.map +1 -1
- package/dist/core/types.d.ts +369 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/factors/device.js +105 -0
- package/dist/factors/device.js.map +1 -0
- package/dist/factors/passkey.js +181 -0
- package/dist/factors/passkey.js.map +1 -0
- package/dist/factors/totp.js +122 -0
- package/dist/factors/totp.js.map +1 -0
- package/dist/providers/anonymous.d.ts +3 -9
- package/dist/providers/anonymous.d.ts.map +1 -1
- package/dist/providers/anonymous.js +1 -18
- package/dist/providers/anonymous.js.map +1 -1
- package/dist/providers/credentials.d.ts +8 -10
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +3 -5
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/device.d.ts +18 -10
- package/dist/providers/device.d.ts.map +1 -1
- package/dist/providers/device.js +4 -8
- package/dist/providers/device.js.map +1 -1
- package/dist/providers/email.d.ts +50 -23
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +58 -34
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/index.d.ts +7 -3
- package/dist/providers/index.js +4 -1
- package/dist/providers/oauth.d.ts.map +1 -1
- package/dist/providers/oauth.js.map +1 -1
- package/dist/providers/passkey.d.ts +12 -9
- package/dist/providers/passkey.d.ts.map +1 -1
- package/dist/providers/passkey.js +1 -7
- package/dist/providers/passkey.js.map +1 -1
- package/dist/providers/password.d.ts +6 -12
- package/dist/providers/password.d.ts.map +1 -1
- package/dist/providers/password.js +189 -89
- package/dist/providers/password.js.map +1 -1
- package/dist/providers/phone.d.ts +40 -11
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +52 -21
- package/dist/providers/phone.js.map +1 -1
- package/dist/providers/sso.d.ts +50 -0
- package/dist/providers/sso.d.ts.map +1 -0
- package/dist/providers/sso.js +34 -0
- package/dist/providers/sso.js.map +1 -0
- package/dist/providers/totp.d.ts +12 -9
- package/dist/providers/totp.d.ts.map +1 -1
- package/dist/providers/totp.js +1 -7
- package/dist/providers/totp.js.map +1 -1
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/invite.js +51 -0
- package/dist/runtime/invite.js.map +1 -0
- package/dist/runtime/proxy.js +70 -0
- package/dist/runtime/proxy.js.map +1 -0
- package/dist/runtime/storage.js +37 -0
- package/dist/runtime/storage.js.map +1 -0
- package/dist/server/auth.d.ts +335 -370
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +204 -123
- package/dist/server/auth.js.map +1 -1
- package/dist/server/authError.d.ts +46 -0
- package/dist/server/authError.d.ts.map +1 -0
- package/dist/server/authError.js +34 -0
- package/dist/server/authError.js.map +1 -0
- package/dist/server/config.d.ts +1 -0
- package/dist/server/{providers.js → config.js} +43 -12
- package/dist/server/config.js.map +1 -0
- package/dist/server/cookies.d.ts +1 -38
- package/dist/server/cookies.js +3 -0
- package/dist/server/cookies.js.map +1 -1
- package/dist/server/core.d.ts +1436 -0
- package/dist/server/core.d.ts.map +1 -0
- package/dist/server/core.js +713 -0
- package/dist/server/core.js.map +1 -0
- package/dist/server/crypto.d.ts +8 -0
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/crypto.js +38 -0
- package/dist/server/crypto.js.map +1 -0
- package/dist/server/db.d.ts +1 -0
- package/dist/server/{implementation/db.js → db.js} +2 -1
- package/dist/server/db.js.map +1 -0
- package/dist/server/device.d.ts +1 -0
- package/dist/server/device.js +109 -0
- package/dist/server/device.js.map +1 -0
- package/dist/server/enterprise/config.d.ts +1 -0
- package/dist/server/enterprise/config.js +46 -0
- package/dist/server/enterprise/config.js.map +1 -0
- package/dist/server/enterprise/domain.d.ts +409 -0
- package/dist/server/enterprise/domain.d.ts.map +1 -0
- package/dist/server/enterprise/domain.js +885 -0
- package/dist/server/enterprise/domain.js.map +1 -0
- package/dist/server/enterprise/http.d.ts +26 -0
- package/dist/server/enterprise/http.d.ts.map +1 -0
- package/dist/server/enterprise/http.js +766 -0
- package/dist/server/enterprise/http.js.map +1 -0
- package/dist/server/enterprise/oidc.d.ts +1 -0
- package/dist/server/enterprise/oidc.js +248 -0
- package/dist/server/enterprise/oidc.js.map +1 -0
- package/dist/server/enterprise/policy.d.ts +1 -0
- package/dist/server/enterprise/policy.js +85 -0
- package/dist/server/enterprise/policy.js.map +1 -0
- package/dist/server/enterprise/saml.d.ts +1 -0
- package/dist/server/enterprise/saml.js +338 -0
- package/dist/server/enterprise/saml.js.map +1 -0
- package/dist/server/enterprise/scim.d.ts +1 -0
- package/dist/server/enterprise/scim.js +97 -0
- package/dist/server/enterprise/scim.js.map +1 -0
- package/dist/server/enterprise/shared.d.ts +5 -0
- package/dist/server/enterprise/shared.d.ts.map +1 -0
- package/dist/server/enterprise/shared.js +51 -0
- package/dist/server/enterprise/shared.js.map +1 -0
- package/dist/server/enterprise/validators.d.ts +1 -0
- package/dist/server/enterprise/validators.js +60 -0
- package/dist/server/enterprise/validators.js.map +1 -0
- package/dist/server/errors.d.ts +33 -1
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +44 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/http.d.ts +59 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +288 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/identity.d.ts +1 -0
- package/dist/server/identity.js +13 -0
- package/dist/server/identity.js.map +1 -0
- package/dist/server/index.d.ts +4 -182
- package/dist/server/index.js +4 -376
- package/dist/server/keys.d.ts +1 -0
- package/dist/{component/server/implementation → server}/keys.js +9 -31
- package/dist/server/keys.js.map +1 -0
- package/dist/server/limits.d.ts +1 -0
- package/dist/server/limits.js +61 -0
- package/dist/server/limits.js.map +1 -0
- package/dist/server/mounts.d.ts +647 -0
- package/dist/server/mounts.d.ts.map +1 -0
- package/dist/server/mounts.js +643 -0
- package/dist/server/mounts.js.map +1 -0
- package/dist/server/mutations/account.d.ts +30 -0
- package/dist/server/mutations/account.d.ts.map +1 -0
- package/dist/server/mutations/account.js +44 -0
- package/dist/server/mutations/account.js.map +1 -0
- package/dist/server/mutations/code.d.ts +30 -0
- package/dist/server/mutations/code.d.ts.map +1 -0
- package/dist/server/{implementation/mutations → mutations}/code.js +7 -4
- package/dist/server/mutations/code.js.map +1 -0
- package/dist/server/mutations/index.d.ts +14 -0
- package/dist/server/mutations/index.js +15 -0
- package/dist/server/mutations/invalidate.d.ts +20 -0
- package/dist/server/mutations/invalidate.d.ts.map +1 -0
- package/dist/server/mutations/invalidate.js +32 -0
- package/dist/server/mutations/invalidate.js.map +1 -0
- package/dist/server/mutations/oauth.d.ts +28 -0
- package/dist/server/mutations/oauth.d.ts.map +1 -0
- package/dist/server/mutations/oauth.js +110 -0
- package/dist/server/mutations/oauth.js.map +1 -0
- package/dist/server/mutations/refresh.d.ts +21 -0
- package/dist/server/mutations/refresh.d.ts.map +1 -0
- package/dist/server/mutations/refresh.js +119 -0
- package/dist/server/mutations/refresh.js.map +1 -0
- package/dist/server/mutations/register.d.ts +38 -0
- package/dist/server/mutations/register.d.ts.map +1 -0
- package/dist/server/mutations/register.js +83 -0
- package/dist/server/mutations/register.js.map +1 -0
- package/dist/server/mutations/retrieve.d.ts +33 -0
- package/dist/server/mutations/retrieve.d.ts.map +1 -0
- package/dist/server/mutations/retrieve.js +65 -0
- package/dist/server/mutations/retrieve.js.map +1 -0
- package/dist/server/mutations/signature.d.ts +22 -0
- package/dist/server/mutations/signature.d.ts.map +1 -0
- package/dist/server/mutations/signature.js +32 -0
- package/dist/server/mutations/signature.js.map +1 -0
- package/dist/server/mutations/signin.d.ts +22 -0
- package/dist/server/mutations/signin.d.ts.map +1 -0
- package/dist/server/{implementation/mutations → mutations}/signin.js +2 -2
- package/dist/server/mutations/signin.js.map +1 -0
- package/dist/server/mutations/signout.d.ts +16 -0
- package/dist/server/mutations/signout.d.ts.map +1 -0
- package/dist/server/mutations/signout.js +27 -0
- package/dist/server/mutations/signout.js.map +1 -0
- package/dist/server/mutations/store/refs.d.ts +12 -0
- package/dist/server/mutations/store/refs.d.ts.map +1 -0
- package/dist/server/mutations/store/refs.js +15 -0
- package/dist/server/mutations/store/refs.js.map +1 -0
- package/dist/server/mutations/store.d.ts +306 -0
- package/dist/server/mutations/store.d.ts.map +1 -0
- package/dist/server/mutations/store.js +85 -0
- package/dist/server/mutations/store.js.map +1 -0
- package/dist/server/mutations/verifier.d.ts +13 -0
- package/dist/server/mutations/verifier.d.ts.map +1 -0
- package/dist/server/mutations/verifier.js +18 -0
- package/dist/server/mutations/verifier.js.map +1 -0
- package/dist/server/mutations/verify.d.ts +26 -0
- package/dist/server/mutations/verify.d.ts.map +1 -0
- package/dist/server/mutations/verify.js +98 -0
- package/dist/server/mutations/verify.js.map +1 -0
- package/dist/server/oauth.d.ts +1 -48
- package/dist/server/oauth.js +107 -64
- package/dist/server/oauth.js.map +1 -1
- package/dist/server/passkey.d.ts +27 -0
- package/dist/server/passkey.d.ts.map +1 -0
- package/dist/server/passkey.js +328 -0
- package/dist/server/passkey.js.map +1 -0
- package/dist/server/redirects.d.ts +1 -0
- package/dist/{component/server/implementation → server}/redirects.js +13 -11
- package/dist/server/redirects.js.map +1 -0
- package/dist/server/refresh.d.ts +1 -0
- package/dist/server/refresh.js +96 -0
- package/dist/server/refresh.js.map +1 -0
- package/dist/server/runtime.d.ts +136 -0
- package/dist/server/runtime.d.ts.map +1 -0
- package/dist/server/runtime.js +413 -0
- package/dist/server/runtime.js.map +1 -0
- package/dist/server/sessions.d.ts +1 -0
- package/dist/{component/server/implementation → server}/sessions.js +14 -8
- package/dist/server/sessions.js.map +1 -0
- package/dist/server/signin.d.ts +1 -0
- package/dist/server/signin.js +201 -0
- package/dist/server/signin.js.map +1 -0
- package/dist/server/ssr.d.ts +226 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/server/ssr.js +786 -0
- package/dist/server/ssr.js.map +1 -0
- package/dist/server/templates.d.ts +1 -21
- package/dist/server/templates.js +2 -1
- package/dist/server/templates.js.map +1 -1
- package/dist/server/tokens.d.ts +1 -0
- package/dist/server/tokens.js +17 -0
- package/dist/server/tokens.js.map +1 -0
- package/dist/server/totp.d.ts +1 -0
- package/dist/server/totp.js +148 -0
- package/dist/server/totp.js.map +1 -0
- package/dist/server/types.d.ts +498 -306
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +108 -1
- package/dist/server/types.js.map +1 -0
- package/dist/server/users.d.ts +1 -0
- package/dist/server/{implementation/users.js → users.js} +54 -35
- package/dist/server/users.js.map +1 -0
- package/dist/server/utils.d.ts +1 -6
- package/dist/server/utils.js +110 -4
- package/dist/server/utils.js.map +1 -1
- package/package.json +49 -46
- package/src/authorization/index.ts +83 -0
- package/src/cli/bin.ts +5 -0
- package/src/cli/command.ts +6 -5
- package/src/cli/index.ts +456 -248
- package/src/cli/keys.ts +3 -0
- package/src/client/core/types.ts +437 -0
- package/src/client/factors/device.ts +160 -0
- package/src/client/factors/passkey.ts +282 -0
- package/src/client/factors/totp.ts +150 -0
- package/src/client/index.ts +745 -989
- package/src/client/runtime/browser.ts +112 -0
- package/src/client/runtime/invite.ts +65 -0
- package/src/client/runtime/proxy.ts +111 -0
- package/src/client/runtime/storage.ts +79 -0
- package/src/component/_generated/api.ts +42 -0
- package/src/component/_generated/component.ts +3123 -102
- package/src/component/functions.ts +38 -22
- package/src/component/index.ts +10 -20
- package/src/component/model.ts +449 -0
- package/src/component/public/enterprise/audit.ts +120 -0
- package/src/component/public/enterprise/core.ts +354 -0
- package/src/component/public/enterprise/domains.ts +323 -0
- package/src/component/public/enterprise/scim.ts +396 -0
- package/src/component/public/enterprise/secrets.ts +132 -0
- package/src/component/public/enterprise/webhooks.ts +306 -0
- package/src/component/public/factors/devices.ts +223 -0
- package/src/component/public/factors/passkeys.ts +242 -0
- package/src/component/public/factors/totp.ts +258 -0
- package/src/component/public/groups/core.ts +481 -0
- package/src/component/public/groups/invites.ts +602 -0
- package/src/component/public/groups/members.ts +409 -0
- package/src/component/public/identity/accounts.ts +206 -0
- package/src/component/public/identity/codes.ts +148 -0
- package/src/component/public/identity/sessions.ts +209 -0
- package/src/component/public/identity/tokens.ts +250 -0
- package/src/component/public/identity/users.ts +354 -0
- package/src/component/public/identity/verifiers.ts +157 -0
- package/src/component/public/security/keys.ts +365 -0
- package/src/component/public/security/limits.ts +173 -0
- package/src/component/public.ts +26 -1766
- package/src/component/schema.ts +273 -100
- package/src/providers/anonymous.ts +10 -20
- package/src/providers/credentials.ts +14 -22
- package/src/providers/device.ts +3 -14
- package/src/providers/email.ts +83 -47
- package/src/providers/index.ts +7 -0
- package/src/providers/oauth.ts +5 -3
- package/src/providers/passkey.ts +0 -13
- package/src/providers/password.ts +307 -130
- package/src/providers/phone.ts +81 -37
- package/src/providers/sso.ts +54 -0
- package/src/providers/totp.ts +0 -13
- package/src/samlify.d.ts +53 -0
- package/src/server/auth.ts +701 -247
- package/src/server/authError.ts +44 -0
- package/src/server/{providers.ts → config.ts} +84 -15
- package/src/server/cookies.ts +8 -1
- package/src/server/core.ts +2095 -0
- package/src/server/crypto.ts +88 -0
- package/src/server/{implementation/db.ts → db.ts} +90 -15
- package/src/server/device.ts +221 -0
- package/src/server/enterprise/config.ts +51 -0
- package/src/server/enterprise/domain.ts +1751 -0
- package/src/server/enterprise/http.ts +1324 -0
- package/src/server/enterprise/oidc.ts +500 -0
- package/src/server/enterprise/policy.ts +128 -0
- package/src/server/enterprise/saml.ts +578 -0
- package/src/server/enterprise/scim.ts +135 -0
- package/src/server/enterprise/shared.ts +134 -0
- package/src/server/enterprise/validators.ts +93 -0
- package/src/server/errors.ts +130 -119
- package/src/server/http.ts +531 -0
- package/src/server/identity.ts +18 -0
- package/src/server/index.ts +32 -650
- package/src/server/{implementation/keys.ts → keys.ts} +16 -44
- package/src/server/limits.ts +134 -0
- package/src/server/mounts.ts +948 -0
- package/src/server/mutations/account.ts +76 -0
- package/src/server/{implementation/mutations → mutations}/code.ts +22 -11
- package/src/server/mutations/index.ts +13 -0
- package/src/server/mutations/invalidate.ts +50 -0
- package/src/server/mutations/oauth.ts +237 -0
- package/src/server/mutations/refresh.ts +298 -0
- package/src/server/mutations/register.ts +200 -0
- package/src/server/mutations/retrieve.ts +109 -0
- package/src/server/mutations/signature.ts +50 -0
- package/src/server/{implementation/mutations → mutations}/signin.ts +9 -7
- package/src/server/mutations/signout.ts +43 -0
- package/src/server/mutations/store/refs.ts +10 -0
- package/src/server/mutations/store.ts +138 -0
- package/src/server/mutations/verifier.ts +34 -0
- package/src/server/mutations/verify.ts +202 -0
- package/src/server/oauth.ts +243 -131
- package/src/server/passkey.ts +784 -0
- package/src/server/{implementation/redirects.ts → redirects.ts} +21 -16
- package/src/server/refresh.ts +222 -0
- package/src/server/runtime.ts +880 -0
- package/src/server/{implementation/sessions.ts → sessions.ts} +33 -25
- package/src/server/signin.ts +438 -0
- package/src/server/ssr.ts +1764 -0
- package/src/server/templates.ts +8 -3
- package/src/server/{implementation/tokens.ts → tokens.ts} +11 -5
- package/src/server/totp.ts +349 -0
- package/src/server/types.ts +972 -207
- package/src/server/{implementation/users.ts → users.ts} +129 -75
- package/src/server/utils.ts +192 -5
- package/src/test.ts +28 -4
- package/dist/bin.cjs +0 -27757
- package/dist/component/providers/email.js +0 -47
- package/dist/component/providers/email.js.map +0 -1
- package/dist/component/public.js.map +0 -1
- package/dist/component/server/implementation/db.js.map +0 -1
- package/dist/component/server/implementation/device.js +0 -135
- package/dist/component/server/implementation/device.js.map +0 -1
- package/dist/component/server/implementation/index.d.ts +0 -870
- package/dist/component/server/implementation/index.d.ts.map +0 -1
- package/dist/component/server/implementation/index.js +0 -610
- package/dist/component/server/implementation/index.js.map +0 -1
- package/dist/component/server/implementation/keys.js.map +0 -1
- package/dist/component/server/implementation/mutations/account.js +0 -39
- package/dist/component/server/implementation/mutations/account.js.map +0 -1
- package/dist/component/server/implementation/mutations/code.js.map +0 -1
- package/dist/component/server/implementation/mutations/index.js +0 -70
- package/dist/component/server/implementation/mutations/index.js.map +0 -1
- package/dist/component/server/implementation/mutations/invalidate.js +0 -29
- package/dist/component/server/implementation/mutations/invalidate.js.map +0 -1
- package/dist/component/server/implementation/mutations/oauth.js +0 -51
- package/dist/component/server/implementation/mutations/oauth.js.map +0 -1
- package/dist/component/server/implementation/mutations/refresh.js +0 -85
- package/dist/component/server/implementation/mutations/refresh.js.map +0 -1
- package/dist/component/server/implementation/mutations/register.js +0 -65
- package/dist/component/server/implementation/mutations/register.js.map +0 -1
- package/dist/component/server/implementation/mutations/retrieve.js +0 -50
- package/dist/component/server/implementation/mutations/retrieve.js.map +0 -1
- package/dist/component/server/implementation/mutations/signature.js +0 -27
- package/dist/component/server/implementation/mutations/signature.js.map +0 -1
- package/dist/component/server/implementation/mutations/signin.js.map +0 -1
- package/dist/component/server/implementation/mutations/signout.js +0 -27
- package/dist/component/server/implementation/mutations/signout.js.map +0 -1
- package/dist/component/server/implementation/mutations/store.js +0 -12
- package/dist/component/server/implementation/mutations/store.js.map +0 -1
- package/dist/component/server/implementation/mutations/verifier.js +0 -16
- package/dist/component/server/implementation/mutations/verifier.js.map +0 -1
- package/dist/component/server/implementation/mutations/verify.js +0 -105
- package/dist/component/server/implementation/mutations/verify.js.map +0 -1
- package/dist/component/server/implementation/passkey.js +0 -307
- package/dist/component/server/implementation/passkey.js.map +0 -1
- package/dist/component/server/implementation/provider.js +0 -19
- package/dist/component/server/implementation/provider.js.map +0 -1
- package/dist/component/server/implementation/ratelimit.js +0 -48
- package/dist/component/server/implementation/ratelimit.js.map +0 -1
- package/dist/component/server/implementation/redirects.js.map +0 -1
- package/dist/component/server/implementation/refresh.js +0 -109
- package/dist/component/server/implementation/refresh.js.map +0 -1
- package/dist/component/server/implementation/sessions.js.map +0 -1
- package/dist/component/server/implementation/signin.js +0 -148
- package/dist/component/server/implementation/signin.js.map +0 -1
- package/dist/component/server/implementation/tokens.js +0 -15
- package/dist/component/server/implementation/tokens.js.map +0 -1
- package/dist/component/server/implementation/totp.js +0 -142
- package/dist/component/server/implementation/totp.js.map +0 -1
- package/dist/component/server/implementation/types.d.ts +0 -42
- package/dist/component/server/implementation/types.d.ts.map +0 -1
- package/dist/component/server/implementation/types.js.map +0 -1
- package/dist/component/server/implementation/users.js.map +0 -1
- package/dist/component/server/implementation/utils.js +0 -56
- package/dist/component/server/implementation/utils.js.map +0 -1
- package/dist/component/server/providers.js.map +0 -1
- package/dist/component/server/templates.js +0 -84
- package/dist/component/server/templates.js.map +0 -1
- package/dist/server/cookies.d.ts.map +0 -1
- package/dist/server/implementation/db.d.ts +0 -86
- package/dist/server/implementation/db.d.ts.map +0 -1
- package/dist/server/implementation/db.js.map +0 -1
- package/dist/server/implementation/device.d.ts +0 -30
- package/dist/server/implementation/device.d.ts.map +0 -1
- package/dist/server/implementation/device.js +0 -135
- package/dist/server/implementation/device.js.map +0 -1
- package/dist/server/implementation/index.d.ts +0 -870
- package/dist/server/implementation/index.d.ts.map +0 -1
- package/dist/server/implementation/index.js +0 -610
- package/dist/server/implementation/index.js.map +0 -1
- package/dist/server/implementation/keys.d.ts +0 -66
- package/dist/server/implementation/keys.d.ts.map +0 -1
- package/dist/server/implementation/keys.js.map +0 -1
- package/dist/server/implementation/mutations/account.d.ts +0 -27
- package/dist/server/implementation/mutations/account.d.ts.map +0 -1
- package/dist/server/implementation/mutations/account.js +0 -39
- package/dist/server/implementation/mutations/account.js.map +0 -1
- package/dist/server/implementation/mutations/code.d.ts +0 -29
- package/dist/server/implementation/mutations/code.d.ts.map +0 -1
- package/dist/server/implementation/mutations/code.js.map +0 -1
- package/dist/server/implementation/mutations/index.d.ts +0 -310
- package/dist/server/implementation/mutations/index.d.ts.map +0 -1
- package/dist/server/implementation/mutations/index.js +0 -70
- package/dist/server/implementation/mutations/index.js.map +0 -1
- package/dist/server/implementation/mutations/invalidate.d.ts +0 -18
- package/dist/server/implementation/mutations/invalidate.d.ts.map +0 -1
- package/dist/server/implementation/mutations/invalidate.js +0 -29
- package/dist/server/implementation/mutations/invalidate.js.map +0 -1
- package/dist/server/implementation/mutations/oauth.d.ts +0 -23
- package/dist/server/implementation/mutations/oauth.d.ts.map +0 -1
- package/dist/server/implementation/mutations/oauth.js +0 -51
- package/dist/server/implementation/mutations/oauth.js.map +0 -1
- package/dist/server/implementation/mutations/refresh.d.ts +0 -20
- package/dist/server/implementation/mutations/refresh.d.ts.map +0 -1
- package/dist/server/implementation/mutations/refresh.js +0 -85
- package/dist/server/implementation/mutations/refresh.js.map +0 -1
- package/dist/server/implementation/mutations/register.d.ts +0 -37
- package/dist/server/implementation/mutations/register.d.ts.map +0 -1
- package/dist/server/implementation/mutations/register.js +0 -65
- package/dist/server/implementation/mutations/register.js.map +0 -1
- package/dist/server/implementation/mutations/retrieve.d.ts +0 -31
- package/dist/server/implementation/mutations/retrieve.d.ts.map +0 -1
- package/dist/server/implementation/mutations/retrieve.js +0 -50
- package/dist/server/implementation/mutations/retrieve.js.map +0 -1
- package/dist/server/implementation/mutations/signature.d.ts +0 -19
- package/dist/server/implementation/mutations/signature.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signature.js +0 -27
- package/dist/server/implementation/mutations/signature.js.map +0 -1
- package/dist/server/implementation/mutations/signin.d.ts +0 -21
- package/dist/server/implementation/mutations/signin.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signin.js.map +0 -1
- package/dist/server/implementation/mutations/signout.d.ts +0 -14
- package/dist/server/implementation/mutations/signout.d.ts.map +0 -1
- package/dist/server/implementation/mutations/signout.js +0 -27
- package/dist/server/implementation/mutations/signout.js.map +0 -1
- package/dist/server/implementation/mutations/store.d.ts +0 -11
- package/dist/server/implementation/mutations/store.d.ts.map +0 -1
- package/dist/server/implementation/mutations/store.js +0 -12
- package/dist/server/implementation/mutations/store.js.map +0 -1
- package/dist/server/implementation/mutations/verifier.d.ts +0 -11
- package/dist/server/implementation/mutations/verifier.d.ts.map +0 -1
- package/dist/server/implementation/mutations/verifier.js +0 -16
- package/dist/server/implementation/mutations/verifier.js.map +0 -1
- package/dist/server/implementation/mutations/verify.d.ts +0 -25
- package/dist/server/implementation/mutations/verify.d.ts.map +0 -1
- package/dist/server/implementation/mutations/verify.js +0 -105
- package/dist/server/implementation/mutations/verify.js.map +0 -1
- package/dist/server/implementation/passkey.d.ts +0 -24
- package/dist/server/implementation/passkey.d.ts.map +0 -1
- package/dist/server/implementation/passkey.js +0 -307
- package/dist/server/implementation/passkey.js.map +0 -1
- package/dist/server/implementation/provider.d.ts +0 -10
- package/dist/server/implementation/provider.d.ts.map +0 -1
- package/dist/server/implementation/provider.js +0 -19
- package/dist/server/implementation/provider.js.map +0 -1
- package/dist/server/implementation/ratelimit.d.ts +0 -10
- package/dist/server/implementation/ratelimit.d.ts.map +0 -1
- package/dist/server/implementation/ratelimit.js +0 -48
- package/dist/server/implementation/ratelimit.js.map +0 -1
- package/dist/server/implementation/redirects.d.ts +0 -10
- package/dist/server/implementation/redirects.d.ts.map +0 -1
- package/dist/server/implementation/redirects.js.map +0 -1
- package/dist/server/implementation/refresh.d.ts +0 -37
- package/dist/server/implementation/refresh.d.ts.map +0 -1
- package/dist/server/implementation/refresh.js +0 -109
- package/dist/server/implementation/refresh.js.map +0 -1
- package/dist/server/implementation/sessions.d.ts +0 -29
- package/dist/server/implementation/sessions.d.ts.map +0 -1
- package/dist/server/implementation/sessions.js.map +0 -1
- package/dist/server/implementation/signin.d.ts +0 -55
- package/dist/server/implementation/signin.d.ts.map +0 -1
- package/dist/server/implementation/signin.js +0 -148
- package/dist/server/implementation/signin.js.map +0 -1
- package/dist/server/implementation/tokens.d.ts +0 -11
- package/dist/server/implementation/tokens.d.ts.map +0 -1
- package/dist/server/implementation/tokens.js +0 -15
- package/dist/server/implementation/tokens.js.map +0 -1
- package/dist/server/implementation/totp.d.ts +0 -31
- package/dist/server/implementation/totp.d.ts.map +0 -1
- package/dist/server/implementation/totp.js +0 -142
- package/dist/server/implementation/totp.js.map +0 -1
- package/dist/server/implementation/types.d.ts +0 -189
- package/dist/server/implementation/types.d.ts.map +0 -1
- package/dist/server/implementation/types.js +0 -97
- package/dist/server/implementation/types.js.map +0 -1
- package/dist/server/implementation/users.d.ts +0 -30
- package/dist/server/implementation/users.d.ts.map +0 -1
- package/dist/server/implementation/users.js.map +0 -1
- package/dist/server/implementation/utils.d.ts +0 -19
- package/dist/server/implementation/utils.d.ts.map +0 -1
- package/dist/server/implementation/utils.js +0 -56
- package/dist/server/implementation/utils.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/oauth.d.ts.map +0 -1
- package/dist/server/providers.d.ts +0 -72
- package/dist/server/providers.d.ts.map +0 -1
- package/dist/server/providers.js.map +0 -1
- package/dist/server/templates.d.ts.map +0 -1
- package/dist/server/utils.d.ts.map +0 -1
- package/dist/server/version.d.ts +0 -5
- package/dist/server/version.d.ts.map +0 -1
- package/dist/server/version.js +0 -6
- package/dist/server/version.js.map +0 -1
- package/src/cli/utils.ts +0 -248
- package/src/server/implementation/device.ts +0 -307
- package/src/server/implementation/index.ts +0 -1583
- package/src/server/implementation/mutations/account.ts +0 -50
- package/src/server/implementation/mutations/index.ts +0 -157
- package/src/server/implementation/mutations/invalidate.ts +0 -42
- package/src/server/implementation/mutations/oauth.ts +0 -73
- package/src/server/implementation/mutations/refresh.ts +0 -175
- package/src/server/implementation/mutations/register.ts +0 -100
- package/src/server/implementation/mutations/retrieve.ts +0 -79
- package/src/server/implementation/mutations/signature.ts +0 -39
- package/src/server/implementation/mutations/signout.ts +0 -35
- package/src/server/implementation/mutations/store.ts +0 -7
- package/src/server/implementation/mutations/verifier.ts +0 -24
- package/src/server/implementation/mutations/verify.ts +0 -194
- package/src/server/implementation/passkey.ts +0 -620
- package/src/server/implementation/provider.ts +0 -36
- package/src/server/implementation/ratelimit.ts +0 -79
- package/src/server/implementation/refresh.ts +0 -172
- package/src/server/implementation/signin.ts +0 -296
- package/src/server/implementation/totp.ts +0 -342
- package/src/server/implementation/types.ts +0 -444
- package/src/server/implementation/utils.ts +0 -91
- package/src/server/version.ts +0 -2
|
@@ -0,0 +1,1436 @@
|
|
|
1
|
+
import { AuthProviderConfig, KeyDoc, KeyScope, ScopeChecker, UserOrderBy, UserWhere } from "./types.js";
|
|
2
|
+
import { Auth, GenericActionCtx, GenericDataModel } from "convex/server";
|
|
3
|
+
import { GenericId } from "convex/values";
|
|
4
|
+
|
|
5
|
+
//#region src/server/core.d.ts
|
|
6
|
+
type ComponentCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">;
|
|
7
|
+
type ComponentReadCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery">;
|
|
8
|
+
type ComponentAuthReadCtx = ComponentReadCtx & {
|
|
9
|
+
auth: Auth;
|
|
10
|
+
};
|
|
11
|
+
type AccountCredentials = {
|
|
12
|
+
id: string;
|
|
13
|
+
secret?: string;
|
|
14
|
+
};
|
|
15
|
+
type CreateAccountArgs = {
|
|
16
|
+
provider: string;
|
|
17
|
+
account: AccountCredentials;
|
|
18
|
+
profile: Record<string, unknown>;
|
|
19
|
+
shouldLinkViaEmail?: boolean;
|
|
20
|
+
shouldLinkViaPhone?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type RetrieveAccountArgs = {
|
|
23
|
+
provider: string;
|
|
24
|
+
account: AccountCredentials;
|
|
25
|
+
};
|
|
26
|
+
type UpdateAccountCredentialsArgs = {
|
|
27
|
+
provider: string;
|
|
28
|
+
account: {
|
|
29
|
+
id: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type CoreDeps = {
|
|
34
|
+
config: any;
|
|
35
|
+
getAuth: () => any;
|
|
36
|
+
callInvalidateSessions: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
37
|
+
userId: GenericId<"User">;
|
|
38
|
+
except?: GenericId<"Session">[];
|
|
39
|
+
}) => Promise<void>;
|
|
40
|
+
callCreateAccountFromCredentials: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: CreateAccountArgs) => Promise<any>;
|
|
41
|
+
callRetrieveAccountWithCredentials: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: RetrieveAccountArgs) => Promise<any>;
|
|
42
|
+
callModifyAccount: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: UpdateAccountCredentialsArgs) => Promise<void>;
|
|
43
|
+
getEnrichCtx: () => <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>) => any;
|
|
44
|
+
inviteTokenAlphabet: string;
|
|
45
|
+
inviteTokenLength: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Build the core auth domains that back the canonical app API surface.
|
|
49
|
+
*
|
|
50
|
+
* Creates the grouped `user`, `session`, `account`, `provider`, `group`,
|
|
51
|
+
* `member`, `invite`, and `key` APIs used by the higher-level auth
|
|
52
|
+
* factory. Each namespace wraps the underlying Convex component functions with
|
|
53
|
+
* application-friendly helpers, result shaping, and documentation-friendly
|
|
54
|
+
* method names.
|
|
55
|
+
*
|
|
56
|
+
* @param deps - Internal component wiring, provider config, and helper
|
|
57
|
+
* functions needed to construct the domain API surface.
|
|
58
|
+
* @returns The core domain namespaces consumed by the auth factory.
|
|
59
|
+
*/
|
|
60
|
+
declare function createCoreDomains(deps: CoreDeps): {
|
|
61
|
+
user: {
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the current user's ID.
|
|
64
|
+
*
|
|
65
|
+
* Checks two sources in order:
|
|
66
|
+
*
|
|
67
|
+
* 1. **Session JWT** — extracts the `userId` from `ctx.auth.getUserIdentity()`.
|
|
68
|
+
* This is the standard path for browser sessions and costs zero DB reads.
|
|
69
|
+
* 2. **API key** — if a `request` is provided and contains a
|
|
70
|
+
* `Bearer sk_*` Authorization header, the key is verified against the
|
|
71
|
+
* database and the owning `userId` is returned.
|
|
72
|
+
*
|
|
73
|
+
* Returns `null` when neither source produces a valid identity.
|
|
74
|
+
*
|
|
75
|
+
* @param ctx - Convex query, mutation, or action context.
|
|
76
|
+
* @param request - Optional incoming `Request` to check for API key auth.
|
|
77
|
+
* Only needed in HTTP actions or server-side handlers.
|
|
78
|
+
* @returns The user's document ID, or `null` if unauthenticated.
|
|
79
|
+
*
|
|
80
|
+
* @example Session auth (queries, mutations)
|
|
81
|
+
* ```ts
|
|
82
|
+
* const userId = await auth.user.id(ctx);
|
|
83
|
+
* if (!userId) return { ok: false, code: "NOT_SIGNED_IN" };
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example API key auth (HTTP actions)
|
|
87
|
+
* ```ts
|
|
88
|
+
* const userId = await auth.user.id(ctx, request);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
id: (ctx: {
|
|
92
|
+
auth: Auth;
|
|
93
|
+
} & Partial<ComponentCtx>, request?: Request) => Promise<string | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Fetch a user document by ID.
|
|
96
|
+
*
|
|
97
|
+
* Results are **cached per-execution** — calling `auth.user.get(ctx, id)`
|
|
98
|
+
* multiple times within the same query or mutation handler for the same
|
|
99
|
+
* `userId` returns the cached result without an additional component read.
|
|
100
|
+
*
|
|
101
|
+
* @param ctx - Convex query or mutation context.
|
|
102
|
+
* @param userId - The user's document ID.
|
|
103
|
+
* @returns The user document, or `null` if not found.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const user = await auth.user.get(ctx, userId);
|
|
108
|
+
* const name = user?.name ?? user?.email ?? "Unknown";
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
get: (ctx: ComponentReadCtx, userId: string) => Promise<any>;
|
|
112
|
+
/**
|
|
113
|
+
* List users with optional filtering, pagination, and ordering.
|
|
114
|
+
*
|
|
115
|
+
* Supports filtering by `email`, `phone`, `name`, and `isAnonymous`.
|
|
116
|
+
* Results are paginated — pass `cursor` from a previous response to
|
|
117
|
+
* load the next page.
|
|
118
|
+
*
|
|
119
|
+
* @param ctx - Convex query or mutation context.
|
|
120
|
+
* @param opts.where - Filter criteria (all optional, combined with AND).
|
|
121
|
+
* @param opts.limit - Max items per page (default 50, max 100).
|
|
122
|
+
* @param opts.cursor - Cursor from a previous `nextCursor` for pagination.
|
|
123
|
+
* @param opts.orderBy - Sort field: `"_creationTime"` (default), `"email"`, etc.
|
|
124
|
+
* @param opts.order - Sort direction: `"asc"` or `"desc"` (default `"desc"`).
|
|
125
|
+
* @returns `{ items, nextCursor }` — `nextCursor` is `null` when no more pages.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* const { items, nextCursor } = await auth.user.list(ctx, {
|
|
130
|
+
* where: { email: "alice@example.com" },
|
|
131
|
+
* limit: 10,
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
list: (ctx: ComponentReadCtx, opts?: {
|
|
136
|
+
where?: UserWhere;
|
|
137
|
+
limit?: number;
|
|
138
|
+
cursor?: string | null;
|
|
139
|
+
orderBy?: UserOrderBy;
|
|
140
|
+
order?: "asc" | "desc";
|
|
141
|
+
}) => Promise<any>;
|
|
142
|
+
/**
|
|
143
|
+
* Convenience method: resolve the current user ID from the session
|
|
144
|
+
* and fetch their full document in one call. Returns `null` if
|
|
145
|
+
* unauthenticated. Equivalent to `auth.user.id(ctx)` then `auth.user.get(ctx, id)`.
|
|
146
|
+
*
|
|
147
|
+
* @param ctx - Convex query or mutation context with `auth` for session lookup.
|
|
148
|
+
* @returns The authenticated user's document, or `null` if unauthenticated.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const viewer = await auth.user.viewer(ctx);
|
|
153
|
+
* if (!viewer) throw new Error("Not signed in");
|
|
154
|
+
* console.log(viewer.name, viewer.email);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
viewer: (ctx: ComponentAuthReadCtx) => Promise<any>;
|
|
158
|
+
/**
|
|
159
|
+
* Patch a user document. Accepts any fields defined on the User schema
|
|
160
|
+
* (e.g. `name`, `image`, `email`, `extend`).
|
|
161
|
+
*
|
|
162
|
+
* @param ctx - Convex mutation context.
|
|
163
|
+
* @param userId - The user's document ID.
|
|
164
|
+
* @param data - Fields to merge into the user document.
|
|
165
|
+
* @returns `{ ok: true, userId }`.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* await auth.user.update(ctx, userId, {
|
|
170
|
+
* name: "Alice Smith",
|
|
171
|
+
* image: "https://example.com/avatar.png",
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
update: (ctx: ComponentCtx, userId: string, data: Record<string, unknown>) => Promise<{
|
|
176
|
+
ok: true;
|
|
177
|
+
userId: string;
|
|
178
|
+
}>;
|
|
179
|
+
/**
|
|
180
|
+
* Set the user's active group. Stored in `user.extend.lastActiveGroup`.
|
|
181
|
+
* Pass `groupId: null` to clear. Useful for multi-workspace apps
|
|
182
|
+
* where the UI needs to remember which workspace is selected.
|
|
183
|
+
*
|
|
184
|
+
* @param ctx - Convex mutation context.
|
|
185
|
+
* @param opts.userId - The user's document ID.
|
|
186
|
+
* @param opts.groupId - Group ID to set as active, or `null` to clear.
|
|
187
|
+
* @returns `{ ok: true, userId, groupId }` confirming the active group was set (or cleared).
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* // Switch to a workspace
|
|
192
|
+
* await auth.user.setActiveGroup(ctx, { userId, groupId: workspaceId });
|
|
193
|
+
*
|
|
194
|
+
* // Clear the active workspace
|
|
195
|
+
* await auth.user.setActiveGroup(ctx, { userId, groupId: null });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
setActiveGroup: (ctx: ComponentCtx, opts: {
|
|
199
|
+
userId: string;
|
|
200
|
+
groupId: string | null;
|
|
201
|
+
}) => Promise<{
|
|
202
|
+
ok: true;
|
|
203
|
+
userId: string;
|
|
204
|
+
groupId: null;
|
|
205
|
+
} | {
|
|
206
|
+
ok: true;
|
|
207
|
+
userId: string;
|
|
208
|
+
groupId: string;
|
|
209
|
+
}>;
|
|
210
|
+
/**
|
|
211
|
+
* Read the user's active group ID from `user.extend.lastActiveGroup`.
|
|
212
|
+
* Returns `null` if no active group is set.
|
|
213
|
+
*
|
|
214
|
+
* @param ctx - Convex query or mutation context.
|
|
215
|
+
* @param opts.userId - The user's document ID.
|
|
216
|
+
* @returns The active group's document ID, or `null` if none is set.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* const activeGroupId = await auth.user.getActiveGroup(ctx, { userId });
|
|
221
|
+
* if (activeGroupId) {
|
|
222
|
+
* const group = await auth.group.get(ctx, activeGroupId);
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
getActiveGroup: (ctx: ComponentReadCtx, opts: {
|
|
227
|
+
userId: string;
|
|
228
|
+
}) => Promise<string | null>;
|
|
229
|
+
/**
|
|
230
|
+
* Delete a user and all associated data.
|
|
231
|
+
*
|
|
232
|
+
* By default (`cascade: true`) deletes the user's sessions, accounts,
|
|
233
|
+
* API keys, group memberships, passkey credentials, and TOTP factors.
|
|
234
|
+
* Pass `{ cascade: false }` to delete only the user document itself.
|
|
235
|
+
*
|
|
236
|
+
* @param ctx - Convex mutation context.
|
|
237
|
+
* @param userId - The user's document ID.
|
|
238
|
+
* @param opts.cascade - Whether to delete related records (default `true`).
|
|
239
|
+
* @returns `{ ok: true, userId }`.
|
|
240
|
+
*/
|
|
241
|
+
delete: (ctx: ComponentCtx, userId: string, opts?: {
|
|
242
|
+
cascade?: boolean;
|
|
243
|
+
}) => Promise<{
|
|
244
|
+
ok: false;
|
|
245
|
+
code: "INVALID_PARAMETERS";
|
|
246
|
+
userId?: undefined;
|
|
247
|
+
} | {
|
|
248
|
+
ok: true;
|
|
249
|
+
userId: string;
|
|
250
|
+
code?: undefined;
|
|
251
|
+
}>;
|
|
252
|
+
};
|
|
253
|
+
session: {
|
|
254
|
+
/**
|
|
255
|
+
* Resolve the current session's ID from the JWT.
|
|
256
|
+
*
|
|
257
|
+
* Extracts the `sessionId` portion of the `subject` claim in the
|
|
258
|
+
* identity token returned by `ctx.auth.getUserIdentity()`. The subject
|
|
259
|
+
* is encoded as `userId<divider>sessionId`, so this splits on the
|
|
260
|
+
* divider and returns the second segment.
|
|
261
|
+
*
|
|
262
|
+
* Returns `null` when there is no authenticated identity (i.e. no
|
|
263
|
+
* valid session JWT).
|
|
264
|
+
*
|
|
265
|
+
* @param ctx - Convex query, mutation, or action context (must include `auth`).
|
|
266
|
+
* @returns The current session's document ID, or `null` if unauthenticated.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* const sessionId = await auth.session.current(ctx);
|
|
271
|
+
* if (!sessionId) throw new Error("Not signed in");
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
current: (ctx: {
|
|
275
|
+
auth: Auth;
|
|
276
|
+
}) => Promise<GenericId<"Session"> | null>;
|
|
277
|
+
/**
|
|
278
|
+
* Invalidate (sign out) all sessions for a given user.
|
|
279
|
+
*
|
|
280
|
+
* Marks every session belonging to `userId` as invalid so that
|
|
281
|
+
* subsequent requests using those session JWTs will fail authentication.
|
|
282
|
+
* Optionally, one or more sessions can be excluded — this is useful
|
|
283
|
+
* when you want to sign out all *other* devices while keeping the
|
|
284
|
+
* current session alive.
|
|
285
|
+
*
|
|
286
|
+
* This method delegates to the component's internal session
|
|
287
|
+
* invalidation RPC.
|
|
288
|
+
*
|
|
289
|
+
* @param ctx - Convex action context.
|
|
290
|
+
* @param args.userId - The user whose sessions should be invalidated.
|
|
291
|
+
* @param args.except - Optional array of session IDs to keep valid.
|
|
292
|
+
* @returns `{ ok: true, userId, except }` confirming the operation.
|
|
293
|
+
*
|
|
294
|
+
* @example Sign out everywhere except the current session
|
|
295
|
+
* ```ts
|
|
296
|
+
* const sessionId = await auth.session.current(ctx);
|
|
297
|
+
* await auth.session.invalidate(ctx, {
|
|
298
|
+
* userId,
|
|
299
|
+
* except: sessionId ? [sessionId] : [],
|
|
300
|
+
* });
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
invalidate: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
304
|
+
userId: GenericId<"User">;
|
|
305
|
+
except?: GenericId<"Session">[];
|
|
306
|
+
}) => Promise<{
|
|
307
|
+
ok: true;
|
|
308
|
+
userId: GenericId<"User">;
|
|
309
|
+
except: GenericId<"Session">[];
|
|
310
|
+
}>;
|
|
311
|
+
/**
|
|
312
|
+
* Fetch a session document by ID.
|
|
313
|
+
*
|
|
314
|
+
* Returns the full session document from the component database, or
|
|
315
|
+
* `null` if no session with the given ID exists. Useful for inspecting
|
|
316
|
+
* session metadata such as creation time or associated device info.
|
|
317
|
+
*
|
|
318
|
+
* @param ctx - Convex query or mutation context.
|
|
319
|
+
* @param sessionId - The session's document ID.
|
|
320
|
+
* @returns The session document, or `null` if not found.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* const session = await auth.session.get(ctx, sessionId);
|
|
325
|
+
* if (!session) throw new Error("Session not found");
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
get: (ctx: ComponentReadCtx, sessionId: string) => Promise<any>;
|
|
329
|
+
/**
|
|
330
|
+
* List all sessions belonging to a user.
|
|
331
|
+
*
|
|
332
|
+
* Returns every session document associated with the given `userId`,
|
|
333
|
+
* including both active and expired sessions. This is useful for
|
|
334
|
+
* building "active sessions" UIs or auditing sign-in history.
|
|
335
|
+
*
|
|
336
|
+
* @param ctx - Convex query or mutation context.
|
|
337
|
+
* @param opts.userId - The user whose sessions to list.
|
|
338
|
+
* @returns An array of session documents.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* const sessions = await auth.session.list(ctx, { userId });
|
|
343
|
+
* console.log(`User has ${sessions.length} sessions`);
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
list: (ctx: ComponentReadCtx, opts: {
|
|
347
|
+
userId: string;
|
|
348
|
+
}) => Promise<any>;
|
|
349
|
+
};
|
|
350
|
+
account: {
|
|
351
|
+
/**
|
|
352
|
+
* Create a new auth account linked to a user.
|
|
353
|
+
*
|
|
354
|
+
* Creates a credentials-based account record for a given provider. If
|
|
355
|
+
* the user does not yet exist, one is created from the supplied
|
|
356
|
+
* `profile`. If `shouldLinkViaEmail` or `shouldLinkViaPhone` is set,
|
|
357
|
+
* the account may be linked to an existing user whose email or phone
|
|
358
|
+
* matches the profile.
|
|
359
|
+
*
|
|
360
|
+
* The `account.secret` (e.g. a hashed password) is optional and
|
|
361
|
+
* depends on the provider type.
|
|
362
|
+
*
|
|
363
|
+
* @param ctx - Convex action context.
|
|
364
|
+
* @param args.provider - The provider ID (e.g. `"password"`, `"credentials"`).
|
|
365
|
+
* @param args.account.id - Provider-specific account identifier (e.g. email address).
|
|
366
|
+
* @param args.account.secret - Optional credential secret (e.g. hashed password).
|
|
367
|
+
* @param args.profile - Profile data used to create or update the user document.
|
|
368
|
+
* @param args.shouldLinkViaEmail - If `true`, link to an existing user by email match.
|
|
369
|
+
* @param args.shouldLinkViaPhone - If `true`, link to an existing user by phone match.
|
|
370
|
+
* @returns `{ ok: true, ...created }` with the created account and user information.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* const result = await auth.account.create(ctx, {
|
|
375
|
+
* provider: "password",
|
|
376
|
+
* account: { id: "alice@example.com", secret: hashedPassword },
|
|
377
|
+
* profile: { email: "alice@example.com", name: "Alice" },
|
|
378
|
+
* });
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
create: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: CreateAccountArgs) => Promise<any>;
|
|
382
|
+
/**
|
|
383
|
+
* Retrieve an auth account by provider and credentials.
|
|
384
|
+
*
|
|
385
|
+
* Looks up an account matching the given provider and account ID,
|
|
386
|
+
* optionally verifying the secret (e.g. password). If the account
|
|
387
|
+
* exists and the credentials are valid, the full account document is
|
|
388
|
+
* returned. Returns `null` if no matching account is found or if the
|
|
389
|
+
* credential verification fails (indicated by a string error from the
|
|
390
|
+
* underlying RPC).
|
|
391
|
+
*
|
|
392
|
+
* @param ctx - Convex action context.
|
|
393
|
+
* @param args.provider - The provider ID (e.g. `"password"`).
|
|
394
|
+
* @param args.account.id - Provider-specific account identifier.
|
|
395
|
+
* @param args.account.secret - Optional credential secret to verify.
|
|
396
|
+
* @returns The account document, or `null` if not found or verification failed.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* const acct = await auth.account.get(ctx, {
|
|
401
|
+
* provider: "password",
|
|
402
|
+
* account: { id: "alice@example.com", secret: plainTextPassword },
|
|
403
|
+
* });
|
|
404
|
+
* if (!acct) throw new Error("Invalid credentials");
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
get: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: RetrieveAccountArgs) => Promise<any>;
|
|
408
|
+
/**
|
|
409
|
+
* Update the credentials (secret) for an existing auth account.
|
|
410
|
+
*
|
|
411
|
+
* Replaces the stored secret for the account identified by `provider`
|
|
412
|
+
* and `account.id`. This is the standard path for password changes
|
|
413
|
+
* and password resets — the new secret is typically a freshly hashed
|
|
414
|
+
* password.
|
|
415
|
+
*
|
|
416
|
+
* @param ctx - Convex action context.
|
|
417
|
+
* @param args.provider - The provider ID (e.g. `"password"`).
|
|
418
|
+
* @param args.account.id - Provider-specific account identifier.
|
|
419
|
+
* @param args.account.secret - The new credential secret to store.
|
|
420
|
+
* @returns `{ ok: true, accountId }` confirming the update.
|
|
421
|
+
*
|
|
422
|
+
* @example Password reset
|
|
423
|
+
* ```ts
|
|
424
|
+
* await auth.account.update(ctx, {
|
|
425
|
+
* provider: "password",
|
|
426
|
+
* account: { id: "alice@example.com", secret: newHashedPassword },
|
|
427
|
+
* });
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
update: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: UpdateAccountCredentialsArgs) => Promise<{
|
|
431
|
+
ok: true;
|
|
432
|
+
accountId: string;
|
|
433
|
+
}>;
|
|
434
|
+
/**
|
|
435
|
+
* Delete an auth account by ID.
|
|
436
|
+
*
|
|
437
|
+
* Removes the account record from the database. As a safety measure,
|
|
438
|
+
* deletion is **refused** if this is the user's only remaining account
|
|
439
|
+
* — the user must always have at least one linked account. If the
|
|
440
|
+
* account is not found, returns an error result instead of throwing.
|
|
441
|
+
*
|
|
442
|
+
* @param ctx - Convex mutation context.
|
|
443
|
+
* @param accountId - The account's document ID.
|
|
444
|
+
* @returns `{ ok: true, accountId }` on success, or
|
|
445
|
+
* `{ ok: false, code: "ACCOUNT_NOT_FOUND" }` if the account does not exist, or
|
|
446
|
+
* `{ ok: false, code: "INVALID_PARAMETERS" }` if it is the user's last account.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```ts
|
|
450
|
+
* const result = await auth.account.delete(ctx, accountId);
|
|
451
|
+
* if (!result.ok) {
|
|
452
|
+
* console.error("Cannot delete account:", result.code);
|
|
453
|
+
* }
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
delete: (ctx: ComponentCtx, accountId: string) => Promise<{
|
|
457
|
+
ok: false;
|
|
458
|
+
code: "ACCOUNT_NOT_FOUND";
|
|
459
|
+
accountId?: undefined;
|
|
460
|
+
} | {
|
|
461
|
+
ok: false;
|
|
462
|
+
code: "INVALID_PARAMETERS";
|
|
463
|
+
accountId?: undefined;
|
|
464
|
+
} | {
|
|
465
|
+
ok: true;
|
|
466
|
+
accountId: string;
|
|
467
|
+
code?: undefined;
|
|
468
|
+
}>;
|
|
469
|
+
/**
|
|
470
|
+
* List all passkey credentials registered for a user.
|
|
471
|
+
*
|
|
472
|
+
* Returns every WebAuthn passkey credential associated with the given
|
|
473
|
+
* `userId`. Each document includes the credential's public key,
|
|
474
|
+
* metadata (such as a human-readable name), and counters used for
|
|
475
|
+
* replay protection.
|
|
476
|
+
*
|
|
477
|
+
* @param ctx - Convex query or mutation context.
|
|
478
|
+
* @param opts.userId - The user whose passkeys to list.
|
|
479
|
+
* @returns An array of passkey credential documents.
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* const passkeys = await auth.account.listPasskeys(ctx, { userId });
|
|
484
|
+
* for (const pk of passkeys) {
|
|
485
|
+
* console.log(pk.name ?? "Unnamed passkey", pk._id);
|
|
486
|
+
* }
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
listPasskeys: (ctx: ComponentReadCtx, opts: {
|
|
490
|
+
userId: string;
|
|
491
|
+
}) => Promise<any>;
|
|
492
|
+
/**
|
|
493
|
+
* Rename a passkey credential.
|
|
494
|
+
*
|
|
495
|
+
* Updates the human-readable `name` metadata on a passkey document.
|
|
496
|
+
* Useful for letting users label their passkeys (e.g. "MacBook Pro",
|
|
497
|
+
* "YubiKey 5").
|
|
498
|
+
*
|
|
499
|
+
* @param ctx - Convex mutation context.
|
|
500
|
+
* @param passkeyId - The passkey credential's document ID.
|
|
501
|
+
* @param name - The new display name for the passkey.
|
|
502
|
+
* @returns `{ ok: true, passkeyId }` confirming the rename.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```ts
|
|
506
|
+
* await auth.account.renamePasskey(ctx, passkeyId, "Work laptop");
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
renamePasskey: (ctx: ComponentCtx, passkeyId: string, name: string) => Promise<{
|
|
510
|
+
ok: true;
|
|
511
|
+
passkeyId: string;
|
|
512
|
+
}>;
|
|
513
|
+
/**
|
|
514
|
+
* Delete a passkey credential.
|
|
515
|
+
*
|
|
516
|
+
* Permanently removes a WebAuthn passkey credential from the database.
|
|
517
|
+
* After deletion, the physical authenticator associated with this
|
|
518
|
+
* credential can no longer be used to sign in.
|
|
519
|
+
*
|
|
520
|
+
* @param ctx - Convex mutation context.
|
|
521
|
+
* @param passkeyId - The passkey credential's document ID.
|
|
522
|
+
* @returns `{ ok: true, passkeyId }` confirming the deletion.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```ts
|
|
526
|
+
* await auth.account.deletePasskey(ctx, passkeyId);
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
deletePasskey: (ctx: ComponentCtx, passkeyId: string) => Promise<{
|
|
530
|
+
ok: true;
|
|
531
|
+
passkeyId: string;
|
|
532
|
+
}>;
|
|
533
|
+
/**
|
|
534
|
+
* List all TOTP (time-based one-time password) factors for a user.
|
|
535
|
+
*
|
|
536
|
+
* Returns every TOTP authenticator factor registered for the given
|
|
537
|
+
* `userId`. Each document includes the secret, issuer, and verification
|
|
538
|
+
* metadata needed for two-factor authentication management UIs.
|
|
539
|
+
*
|
|
540
|
+
* @param ctx - Convex query or mutation context.
|
|
541
|
+
* @param opts.userId - The user whose TOTP factors to list.
|
|
542
|
+
* @returns An array of TOTP factor documents.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts
|
|
546
|
+
* const totps = await auth.account.listTotps(ctx, { userId });
|
|
547
|
+
* const has2FA = totps.length > 0;
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
listTotps: (ctx: ComponentReadCtx, opts: {
|
|
551
|
+
userId: string;
|
|
552
|
+
}) => Promise<any>;
|
|
553
|
+
/**
|
|
554
|
+
* Delete a TOTP factor.
|
|
555
|
+
*
|
|
556
|
+
* Permanently removes a TOTP authenticator factor from the database.
|
|
557
|
+
* After deletion, codes generated by the corresponding authenticator
|
|
558
|
+
* app will no longer be accepted for two-factor authentication.
|
|
559
|
+
*
|
|
560
|
+
* @param ctx - Convex mutation context.
|
|
561
|
+
* @param totpId - The TOTP factor's document ID.
|
|
562
|
+
* @returns `{ ok: true, totpId }` confirming the deletion.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* await auth.account.deleteTotp(ctx, totpId);
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
deleteTotp: (ctx: ComponentCtx, totpId: string) => Promise<{
|
|
570
|
+
ok: true;
|
|
571
|
+
totpId: string;
|
|
572
|
+
}>;
|
|
573
|
+
};
|
|
574
|
+
provider: {
|
|
575
|
+
/**
|
|
576
|
+
* Sign in through a specific provider from server-side code.
|
|
577
|
+
*
|
|
578
|
+
* Materializes the supplied provider config, runs the standard sign-in
|
|
579
|
+
* flow, and returns the resulting `userId` and `sessionId` when the
|
|
580
|
+
* provider completes authentication immediately. Returns `null` for
|
|
581
|
+
* providers that require additional client-side steps (for example
|
|
582
|
+
* redirects, email verification, or other non-immediate flows).
|
|
583
|
+
*
|
|
584
|
+
* This helper is useful for trusted server flows where you already know
|
|
585
|
+
* which provider should handle the sign-in and want the same behavior as
|
|
586
|
+
* the public auth API without generating tokens for the client.
|
|
587
|
+
*
|
|
588
|
+
* @param ctx - Convex action context.
|
|
589
|
+
* @param providerConfig - Provider configuration object to materialize and use.
|
|
590
|
+
* @param args.accountId - Optional account document ID to sign in with directly.
|
|
591
|
+
* @param args.params - Optional provider-specific parameters forwarded to the sign-in flow.
|
|
592
|
+
* @returns `{ userId, sessionId }` when sign-in succeeds immediately, or `null`
|
|
593
|
+
* when the provider does not produce an immediate signed-in result.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* const signedIn = await auth.provider.signIn(ctx, passwordProvider, {
|
|
598
|
+
* params: { email: "alice@example.com", password: "secret" },
|
|
599
|
+
* });
|
|
600
|
+
*
|
|
601
|
+
* if (!signedIn) {
|
|
602
|
+
* throw new Error("Provider requires another auth step");
|
|
603
|
+
* }
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
signIn: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, providerConfig: AuthProviderConfig, args: {
|
|
607
|
+
accountId?: GenericId<"Account">;
|
|
608
|
+
params?: Record<string, unknown>;
|
|
609
|
+
}) => Promise<{
|
|
610
|
+
userId: GenericId<"User">;
|
|
611
|
+
sessionId: GenericId<"Session">;
|
|
612
|
+
} | null>;
|
|
613
|
+
};
|
|
614
|
+
group: {
|
|
615
|
+
/**
|
|
616
|
+
* Create a new group (organization, workspace, team, etc.).
|
|
617
|
+
*
|
|
618
|
+
* Groups are hierarchical — set `parentGroupId` to nest under an existing
|
|
619
|
+
* group, or omit it to create a root-level group. Two denormalized fields
|
|
620
|
+
* are maintained automatically:
|
|
621
|
+
*
|
|
622
|
+
* - `rootGroupId` — the root ancestor (self-referencing for root groups).
|
|
623
|
+
* - `isRoot` — `true` when the group has no parent.
|
|
624
|
+
*
|
|
625
|
+
* @param ctx - Convex mutation context.
|
|
626
|
+
* @param data.name - Display name for the group.
|
|
627
|
+
* @param data.slug - URL-safe slug (optional).
|
|
628
|
+
* @param data.type - App-defined type string (e.g. `"workspace"`, `"team"`).
|
|
629
|
+
* @param data.parentGroupId - Nest under this group. Omit for a root group.
|
|
630
|
+
* @param data.tags - Faceted classification tags (normalized at write time).
|
|
631
|
+
* @param data.extend - Arbitrary app-specific metadata.
|
|
632
|
+
* @returns `{ ok: true, groupId }`.
|
|
633
|
+
*
|
|
634
|
+
* @example Root group
|
|
635
|
+
* ```ts
|
|
636
|
+
* const { groupId } = await auth.group.create(ctx, {
|
|
637
|
+
* name: "Acme Corp", type: "workspace",
|
|
638
|
+
* });
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @example Nested team
|
|
642
|
+
* ```ts
|
|
643
|
+
* const { groupId } = await auth.group.create(ctx, {
|
|
644
|
+
* name: "Engineering", parentGroupId: orgId, type: "team",
|
|
645
|
+
* });
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
create: (ctx: ComponentCtx, data: {
|
|
649
|
+
name: string;
|
|
650
|
+
slug?: string;
|
|
651
|
+
type?: string;
|
|
652
|
+
parentGroupId?: string;
|
|
653
|
+
tags?: Array<{
|
|
654
|
+
key: string;
|
|
655
|
+
value: string;
|
|
656
|
+
}>;
|
|
657
|
+
extend?: Record<string, unknown>;
|
|
658
|
+
}) => Promise<{
|
|
659
|
+
ok: true;
|
|
660
|
+
groupId: string;
|
|
661
|
+
}>;
|
|
662
|
+
/**
|
|
663
|
+
* Fetch a group document by ID.
|
|
664
|
+
*
|
|
665
|
+
* Results are **cached per-execution** — calling `auth.group.get(ctx, id)`
|
|
666
|
+
* multiple times within the same handler for the same `groupId` returns
|
|
667
|
+
* the cached result without an additional component read.
|
|
668
|
+
*
|
|
669
|
+
* @param ctx - Convex query or mutation context.
|
|
670
|
+
* @param groupId - The group's document ID.
|
|
671
|
+
* @returns The group document (including `rootGroupId`, `isRoot`), or `null`.
|
|
672
|
+
*/
|
|
673
|
+
get: (ctx: ComponentReadCtx, groupId: string) => Promise<any>;
|
|
674
|
+
/**
|
|
675
|
+
* List groups with optional filtering, pagination, and ordering.
|
|
676
|
+
*
|
|
677
|
+
* Supports filtering by `slug`, `type`, `parentGroupId`, `name`,
|
|
678
|
+
* `isRoot`, and tags (`tagsAll`, `tagsAny`). The `isRoot` and
|
|
679
|
+
* `parentGroupId` filters use dedicated indexes for efficient queries.
|
|
680
|
+
*
|
|
681
|
+
* @param ctx - Convex query or mutation context.
|
|
682
|
+
* @param opts.where - Filter criteria (all optional, combined with AND).
|
|
683
|
+
* @param opts.where.isRoot - `true` to find root groups, `false` for nested.
|
|
684
|
+
* @param opts.where.parentGroupId - List direct children of this group.
|
|
685
|
+
* @param opts.limit - Max items per page (default 50, max 100).
|
|
686
|
+
* @param opts.cursor - Cursor from a previous `nextCursor`.
|
|
687
|
+
* @param opts.orderBy - Sort field: `"_creationTime"`, `"name"`, `"slug"`, `"type"`.
|
|
688
|
+
* @param opts.order - Sort direction: `"asc"` or `"desc"`.
|
|
689
|
+
* @returns `{ items, nextCursor }`.
|
|
690
|
+
*
|
|
691
|
+
* @example List root workspaces
|
|
692
|
+
* ```ts
|
|
693
|
+
* const { items } = await auth.group.list(ctx, {
|
|
694
|
+
* where: { isRoot: true },
|
|
695
|
+
* orderBy: "name", order: "asc",
|
|
696
|
+
* });
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @example List children of a group
|
|
700
|
+
* ```ts
|
|
701
|
+
* const { items } = await auth.group.list(ctx, {
|
|
702
|
+
* where: { parentGroupId: orgId },
|
|
703
|
+
* });
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
list: (ctx: ComponentReadCtx, opts?: {
|
|
707
|
+
where?: {
|
|
708
|
+
slug?: string;
|
|
709
|
+
type?: string;
|
|
710
|
+
parentGroupId?: string;
|
|
711
|
+
name?: string;
|
|
712
|
+
isRoot?: boolean;
|
|
713
|
+
tagsAll?: Array<{
|
|
714
|
+
key: string;
|
|
715
|
+
value: string;
|
|
716
|
+
}>;
|
|
717
|
+
tagsAny?: Array<{
|
|
718
|
+
key: string;
|
|
719
|
+
value: string;
|
|
720
|
+
}>;
|
|
721
|
+
};
|
|
722
|
+
limit?: number;
|
|
723
|
+
cursor?: string | null;
|
|
724
|
+
orderBy?: "_creationTime" | "name" | "slug" | "type";
|
|
725
|
+
order?: "asc" | "desc";
|
|
726
|
+
}) => Promise<any>;
|
|
727
|
+
/**
|
|
728
|
+
* Patch a group document.
|
|
729
|
+
*
|
|
730
|
+
* If `parentGroupId` is changed, the group's `rootGroupId` and `isRoot`
|
|
731
|
+
* fields are recomputed automatically and cascaded to all descendants.
|
|
732
|
+
*
|
|
733
|
+
* @param ctx - Convex mutation context.
|
|
734
|
+
* @param groupId - The group's document ID.
|
|
735
|
+
* @param data - Fields to merge (e.g. `name`, `slug`, `tags`, `parentGroupId`).
|
|
736
|
+
* @returns `{ ok: true, groupId }`.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* await auth.group.update(ctx, groupId, {
|
|
741
|
+
* name: "Acme Corp (renamed)",
|
|
742
|
+
* slug: "acme-corp",
|
|
743
|
+
* });
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
update: (ctx: ComponentCtx, groupId: string, data: Record<string, unknown>) => Promise<{
|
|
747
|
+
ok: true;
|
|
748
|
+
groupId: string;
|
|
749
|
+
}>;
|
|
750
|
+
/**
|
|
751
|
+
* Delete a group and recursively cascade to all descendant groups,
|
|
752
|
+
* their members, invites, and tags.
|
|
753
|
+
*
|
|
754
|
+
* @param ctx - Convex mutation context.
|
|
755
|
+
* @param groupId - The group's document ID.
|
|
756
|
+
* @returns `{ ok: true, groupId }`.
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* await auth.group.delete(ctx, groupId);
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
delete: (ctx: ComponentCtx, groupId: string) => Promise<{
|
|
764
|
+
ok: true;
|
|
765
|
+
groupId: string;
|
|
766
|
+
}>;
|
|
767
|
+
/**
|
|
768
|
+
* Walk up the group hierarchy from `groupId` and return all ancestor
|
|
769
|
+
* groups in order from immediate parent to root. Detects cycles and
|
|
770
|
+
* respects `maxDepth` (default 32).
|
|
771
|
+
*
|
|
772
|
+
* @param ctx - Convex query or mutation context.
|
|
773
|
+
* @param opts.groupId - Starting group ID.
|
|
774
|
+
* @param opts.maxDepth - Max levels to traverse (default 32).
|
|
775
|
+
* @param opts.includeSelf - Include the starting group in the result.
|
|
776
|
+
* @returns `{ ancestors, cycleDetected, maxDepthReached }`.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* ```ts
|
|
780
|
+
* const { ancestors } = await auth.group.ancestors(ctx, {
|
|
781
|
+
* groupId: teamId,
|
|
782
|
+
* includeSelf: true,
|
|
783
|
+
* });
|
|
784
|
+
* const rootOrg = ancestors[ancestors.length - 1];
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
ancestors: (ctx: ComponentReadCtx, opts: {
|
|
788
|
+
groupId: string;
|
|
789
|
+
maxDepth?: number;
|
|
790
|
+
includeSelf?: boolean;
|
|
791
|
+
}) => Promise<{
|
|
792
|
+
ancestors: any[];
|
|
793
|
+
cycleDetected: boolean;
|
|
794
|
+
maxDepthReached: boolean;
|
|
795
|
+
}>;
|
|
796
|
+
};
|
|
797
|
+
member: {
|
|
798
|
+
/**
|
|
799
|
+
* Add a user to a group with optional role IDs.
|
|
800
|
+
*
|
|
801
|
+
* Role IDs are validated against the roles defined in `defineRoles()` —
|
|
802
|
+
* invalid IDs return `{ ok: false, code: "INVALID_ROLE_IDS" }`.
|
|
803
|
+
* Throws `DUPLICATE_MEMBERSHIP` if the user is already a member.
|
|
804
|
+
*
|
|
805
|
+
* @param ctx - Convex mutation context.
|
|
806
|
+
* @param data.groupId - The group to add the user to.
|
|
807
|
+
* @param data.userId - The user's document ID.
|
|
808
|
+
* @param data.roleIds - Role IDs from `defineRoles()` (optional).
|
|
809
|
+
* @param data.status - Membership status string (optional, app-defined).
|
|
810
|
+
* @param data.extend - Arbitrary app-specific metadata.
|
|
811
|
+
* @returns `{ ok: true, memberId }` or `{ ok: false, code, invalidRoleIds }`.
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```ts
|
|
815
|
+
* const { memberId } = await auth.member.create(ctx, {
|
|
816
|
+
* groupId: orgId,
|
|
817
|
+
* userId,
|
|
818
|
+
* roleIds: [roles.orgAdmin.id],
|
|
819
|
+
* });
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
create: (ctx: ComponentCtx, data: {
|
|
823
|
+
groupId: string;
|
|
824
|
+
userId: string;
|
|
825
|
+
roleIds?: string[];
|
|
826
|
+
status?: string;
|
|
827
|
+
extend?: Record<string, unknown>;
|
|
828
|
+
}) => Promise<{
|
|
829
|
+
ok: false;
|
|
830
|
+
code: "INVALID_ROLE_IDS";
|
|
831
|
+
invalidRoleIds: string[];
|
|
832
|
+
memberId?: undefined;
|
|
833
|
+
} | {
|
|
834
|
+
ok: true;
|
|
835
|
+
memberId: string;
|
|
836
|
+
code?: undefined;
|
|
837
|
+
invalidRoleIds?: undefined;
|
|
838
|
+
}>;
|
|
839
|
+
/**
|
|
840
|
+
* Fetch a membership document by its document ID.
|
|
841
|
+
*
|
|
842
|
+
* @param ctx - Convex query or mutation context.
|
|
843
|
+
* @param memberId - The membership document ID.
|
|
844
|
+
* @returns The membership document, or `null` if not found.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```ts
|
|
848
|
+
* const membership = await auth.member.get(ctx, memberId);
|
|
849
|
+
* if (!membership) throw new Error("Membership not found");
|
|
850
|
+
* console.log(membership.roleIds, membership.groupId);
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
get: (ctx: ComponentReadCtx, memberId: string) => Promise<any>;
|
|
854
|
+
/**
|
|
855
|
+
* List memberships with optional filtering and pagination.
|
|
856
|
+
*
|
|
857
|
+
* Supports filtering by `groupId`, `userId`, `roleId`, and `status`.
|
|
858
|
+
* When `groupId` and `status` are both provided, a compound index
|
|
859
|
+
* is used for efficient queries.
|
|
860
|
+
*
|
|
861
|
+
* @param ctx - Convex query or mutation context.
|
|
862
|
+
* @param opts.where - Filter criteria (all optional).
|
|
863
|
+
* @param opts.limit - Max items per page (default 50, max 100).
|
|
864
|
+
* @param opts.cursor - Cursor for pagination.
|
|
865
|
+
* @param opts.orderBy - Sort field: `"_creationTime"` or `"status"`.
|
|
866
|
+
* @param opts.order - Sort direction: `"asc"` or `"desc"`.
|
|
867
|
+
* @returns `{ items, nextCursor }`.
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* ```ts
|
|
871
|
+
* const { items } = await auth.member.list(ctx, {
|
|
872
|
+
* where: { groupId: orgId },
|
|
873
|
+
* limit: 20,
|
|
874
|
+
* orderBy: "_creationTime",
|
|
875
|
+
* order: "asc",
|
|
876
|
+
* });
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
list: (ctx: ComponentReadCtx, opts?: {
|
|
880
|
+
where?: {
|
|
881
|
+
groupId?: string;
|
|
882
|
+
userId?: string;
|
|
883
|
+
roleId?: string;
|
|
884
|
+
status?: string;
|
|
885
|
+
};
|
|
886
|
+
limit?: number;
|
|
887
|
+
cursor?: string | null;
|
|
888
|
+
orderBy?: "_creationTime" | "status";
|
|
889
|
+
order?: "asc" | "desc";
|
|
890
|
+
}) => Promise<any>;
|
|
891
|
+
/**
|
|
892
|
+
* Remove a membership by its document ID.
|
|
893
|
+
*
|
|
894
|
+
* @param ctx - Convex mutation context.
|
|
895
|
+
* @param memberId - The membership document ID.
|
|
896
|
+
* @returns `{ ok: true, memberId }`.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```ts
|
|
900
|
+
* await auth.member.delete(ctx, memberId);
|
|
901
|
+
* ```
|
|
902
|
+
*/
|
|
903
|
+
delete: (ctx: ComponentCtx, memberId: string) => Promise<{
|
|
904
|
+
ok: true;
|
|
905
|
+
memberId: string;
|
|
906
|
+
}>;
|
|
907
|
+
/**
|
|
908
|
+
* Patch a membership's `roleIds`, `status`, or `extend` fields.
|
|
909
|
+
* Role IDs are validated against `defineRoles()`.
|
|
910
|
+
*
|
|
911
|
+
* @param ctx - Convex mutation context.
|
|
912
|
+
* @param memberId - The membership document ID.
|
|
913
|
+
* @param data - Fields to merge. `roleIds` are validated.
|
|
914
|
+
* @returns `{ ok: true, memberId }` or `{ ok: false, code: "INVALID_ROLE_IDS" }`.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* await auth.member.update(ctx, memberId, {
|
|
919
|
+
* roleIds: [roles.orgAdmin.id],
|
|
920
|
+
* status: "active",
|
|
921
|
+
* });
|
|
922
|
+
* ```
|
|
923
|
+
*/
|
|
924
|
+
update: (ctx: ComponentCtx, memberId: string, data: Record<string, unknown>) => Promise<{
|
|
925
|
+
ok: false;
|
|
926
|
+
code: "INVALID_ROLE_IDS";
|
|
927
|
+
invalidRoleIds: string[];
|
|
928
|
+
memberId?: undefined;
|
|
929
|
+
} | {
|
|
930
|
+
ok: true;
|
|
931
|
+
memberId: string;
|
|
932
|
+
code?: undefined;
|
|
933
|
+
invalidRoleIds?: undefined;
|
|
934
|
+
}>;
|
|
935
|
+
/**
|
|
936
|
+
* Resolve a user's membership in a group, optionally walking the
|
|
937
|
+
* hierarchy and checking grants.
|
|
938
|
+
*
|
|
939
|
+
* **Default (no flags):** Direct lookup at `groupId` only — fast,
|
|
940
|
+
* 1 component read. Replaces the old `getByUserAndGroup`.
|
|
941
|
+
*
|
|
942
|
+
* **`ancestry: true`:** Walk the group hierarchy from `groupId` up
|
|
943
|
+
* to root, returning the first matching membership. Includes
|
|
944
|
+
* `traversedGroupIds` in the result. Expensive (N reads).
|
|
945
|
+
*
|
|
946
|
+
* **`grants: [...]`:** Check if the user has all specified grants.
|
|
947
|
+
* Works at the direct level by default. Combine with
|
|
948
|
+
* `ancestry: true` to check inherited grants.
|
|
949
|
+
*
|
|
950
|
+
* @param ctx - Convex query or mutation context.
|
|
951
|
+
* @param opts.userId - The user's document ID.
|
|
952
|
+
* @param opts.groupId - The group to check membership in.
|
|
953
|
+
* @param opts.ancestry - Walk the hierarchy (default `false`).
|
|
954
|
+
* @param opts.grants - Grant strings to check (optional).
|
|
955
|
+
* @param opts.roleIds - Role IDs to filter by (optional).
|
|
956
|
+
* @param opts.maxDepth - Max hierarchy levels (default 32, only with ancestry).
|
|
957
|
+
* @returns `{ ok, membership, roleIds, grants, missingGrants, ... }`.
|
|
958
|
+
* `ok` is `true` when membership exists and all requested grants are satisfied.
|
|
959
|
+
*
|
|
960
|
+
* @example Direct lookup
|
|
961
|
+
* ```ts
|
|
962
|
+
* const result = await auth.member.resolve(ctx, { userId, groupId });
|
|
963
|
+
* if (!result.membership) return { ok: false, code: "NOT_A_MEMBER" };
|
|
964
|
+
* ```
|
|
965
|
+
*
|
|
966
|
+
* @example Check grants (no hierarchy walk)
|
|
967
|
+
* ```ts
|
|
968
|
+
* const result = await auth.member.resolve(ctx, {
|
|
969
|
+
* userId, groupId, grants: ["issues.create"],
|
|
970
|
+
* });
|
|
971
|
+
* if (!result.ok) return { ok: false, code: "FORBIDDEN" };
|
|
972
|
+
* ```
|
|
973
|
+
*
|
|
974
|
+
* @example Walk hierarchy + check grants
|
|
975
|
+
* ```ts
|
|
976
|
+
* const result = await auth.member.resolve(ctx, {
|
|
977
|
+
* userId, groupId: teamId, ancestry: true, grants: ["issues.create"],
|
|
978
|
+
* });
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
resolve: (ctx: ComponentReadCtx, opts: {
|
|
982
|
+
userId: string;
|
|
983
|
+
groupId: string;
|
|
984
|
+
ancestry?: boolean;
|
|
985
|
+
roleIds?: string[];
|
|
986
|
+
grants?: string[];
|
|
987
|
+
maxDepth?: number;
|
|
988
|
+
}) => Promise<{
|
|
989
|
+
ok: false;
|
|
990
|
+
membership: null;
|
|
991
|
+
matchedGroupId: null;
|
|
992
|
+
roleIds: string[];
|
|
993
|
+
grants: string[];
|
|
994
|
+
missingGrants: string[];
|
|
995
|
+
depth: null;
|
|
996
|
+
isDirect: boolean;
|
|
997
|
+
isInherited: boolean;
|
|
998
|
+
traversedGroupIds: string[];
|
|
999
|
+
code: "INVALID_ROLE_IDS";
|
|
1000
|
+
invalidRoleIds: string[];
|
|
1001
|
+
} | {
|
|
1002
|
+
ok: boolean;
|
|
1003
|
+
membership: any;
|
|
1004
|
+
matchedGroupId: string | null;
|
|
1005
|
+
roleIds: any;
|
|
1006
|
+
grants: string[];
|
|
1007
|
+
missingGrants: string[];
|
|
1008
|
+
depth: number | null;
|
|
1009
|
+
isDirect: boolean;
|
|
1010
|
+
isInherited: boolean;
|
|
1011
|
+
traversedGroupIds: string[];
|
|
1012
|
+
code?: undefined;
|
|
1013
|
+
invalidRoleIds?: undefined;
|
|
1014
|
+
}>;
|
|
1015
|
+
};
|
|
1016
|
+
invite: {
|
|
1017
|
+
/**
|
|
1018
|
+
* Create a pending invite. Returns a one-time `token` the recipient
|
|
1019
|
+
* uses to accept. Optionally scoped to a group with role IDs.
|
|
1020
|
+
*
|
|
1021
|
+
* @param ctx - Convex mutation context.
|
|
1022
|
+
* @param data.groupId - The group to invite the user to (optional).
|
|
1023
|
+
* @param data.invitedByUserId - The user who created this invite (optional).
|
|
1024
|
+
* @param data.email - The invitee's email address (optional).
|
|
1025
|
+
* @param data.roleIds - Role IDs from `defineRoles()` to assign on acceptance (optional).
|
|
1026
|
+
* @param data.expiresTime - Expiration timestamp in ms since epoch (optional).
|
|
1027
|
+
* @param data.extend - Arbitrary app-specific metadata (optional).
|
|
1028
|
+
* @returns `{ ok: true, inviteId, token }` or `{ ok: false, code: "INVALID_ROLE_IDS" }`.
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```ts
|
|
1032
|
+
* const { token } = await auth.invite.create(ctx, {
|
|
1033
|
+
* groupId, email: "alice@example.com", roleIds: [roles.member.id],
|
|
1034
|
+
* });
|
|
1035
|
+
* ```
|
|
1036
|
+
*/
|
|
1037
|
+
create: (ctx: ComponentCtx, data: {
|
|
1038
|
+
groupId?: string;
|
|
1039
|
+
invitedByUserId?: string;
|
|
1040
|
+
email?: string;
|
|
1041
|
+
roleIds?: string[];
|
|
1042
|
+
expiresTime?: number;
|
|
1043
|
+
extend?: Record<string, unknown>;
|
|
1044
|
+
}) => Promise<{
|
|
1045
|
+
ok: false;
|
|
1046
|
+
code: "INVALID_ROLE_IDS";
|
|
1047
|
+
invalidRoleIds: string[];
|
|
1048
|
+
inviteId?: undefined;
|
|
1049
|
+
token?: undefined;
|
|
1050
|
+
} | {
|
|
1051
|
+
ok: true;
|
|
1052
|
+
inviteId: string;
|
|
1053
|
+
token: string;
|
|
1054
|
+
code?: undefined;
|
|
1055
|
+
invalidRoleIds?: undefined;
|
|
1056
|
+
}>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Fetch an invite document by ID.
|
|
1059
|
+
*
|
|
1060
|
+
* Returns the full invite document including its status, email,
|
|
1061
|
+
* group, role IDs, and token hash. Useful for displaying invite
|
|
1062
|
+
* details or checking status before performing actions.
|
|
1063
|
+
*
|
|
1064
|
+
* @param ctx - Convex query or mutation context.
|
|
1065
|
+
* @param inviteId - The invite's document ID.
|
|
1066
|
+
* @returns The invite document, or `null` if not found.
|
|
1067
|
+
*
|
|
1068
|
+
* @example
|
|
1069
|
+
* ```ts
|
|
1070
|
+
* const invite = await auth.invite.get(ctx, inviteId);
|
|
1071
|
+
* if (invite?.status === "pending") {
|
|
1072
|
+
* // show invite details
|
|
1073
|
+
* }
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1076
|
+
get: (ctx: ComponentReadCtx, inviteId: string) => Promise<any>;
|
|
1077
|
+
token: {
|
|
1078
|
+
/**
|
|
1079
|
+
* Look up an invite by its raw token string.
|
|
1080
|
+
*
|
|
1081
|
+
* Hashes the raw token and queries the database for a matching
|
|
1082
|
+
* invite. This is the standard path for invite-link landing pages
|
|
1083
|
+
* where the token is extracted from the URL.
|
|
1084
|
+
*
|
|
1085
|
+
* @param ctx - Convex query or mutation context.
|
|
1086
|
+
* @param token - The raw invite token string from the invite link.
|
|
1087
|
+
* @returns The invite document, or `null` if no matching invite exists.
|
|
1088
|
+
*
|
|
1089
|
+
* @example
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* const invite = await auth.invite.token.get(ctx, tokenFromUrl);
|
|
1092
|
+
* if (!invite || invite.status !== "pending") {
|
|
1093
|
+
* throw new Error("Invalid or expired invite");
|
|
1094
|
+
* }
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
get: (ctx: ComponentReadCtx, token: string) => Promise<any>;
|
|
1098
|
+
/**
|
|
1099
|
+
* Accept an invite by token. Creates a membership and marks the invite as accepted.
|
|
1100
|
+
*
|
|
1101
|
+
* Hashes the raw token, finds the matching invite, creates a group
|
|
1102
|
+
* membership with the invite's role IDs, and transitions the invite
|
|
1103
|
+
* status to `"accepted"`.
|
|
1104
|
+
*
|
|
1105
|
+
* @param ctx - Convex mutation context.
|
|
1106
|
+
* @param args.token - The raw invite token string.
|
|
1107
|
+
* @param args.acceptedByUserId - The user accepting the invite.
|
|
1108
|
+
* @returns `{ ok: true, ...result }` with the created membership details.
|
|
1109
|
+
*
|
|
1110
|
+
* @example
|
|
1111
|
+
* ```ts
|
|
1112
|
+
* const result = await auth.invite.token.accept(ctx, {
|
|
1113
|
+
* token: tokenFromUrl,
|
|
1114
|
+
* acceptedByUserId: userId,
|
|
1115
|
+
* });
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
accept: (ctx: ComponentCtx, args: {
|
|
1119
|
+
token: string;
|
|
1120
|
+
acceptedByUserId: string;
|
|
1121
|
+
}) => Promise<any>;
|
|
1122
|
+
};
|
|
1123
|
+
/**
|
|
1124
|
+
* List invites with optional filtering by group, status, email, etc.
|
|
1125
|
+
* Results are paginated.
|
|
1126
|
+
*
|
|
1127
|
+
* @param ctx - Convex query or mutation context.
|
|
1128
|
+
* @param opts.where - Filter criteria (all optional).
|
|
1129
|
+
* @param opts.where.status - `"pending"`, `"accepted"`, `"revoked"`, or `"expired"`.
|
|
1130
|
+
* @param opts.limit - Max items per page (default 50, max 100).
|
|
1131
|
+
* @param opts.cursor - Cursor from a previous `nextCursor` for pagination.
|
|
1132
|
+
* @param opts.orderBy - Sort field: `"_creationTime"`, `"status"`, `"email"`,
|
|
1133
|
+
* `"expiresTime"`, or `"acceptedTime"`.
|
|
1134
|
+
* @param opts.order - Sort direction: `"asc"` or `"desc"`.
|
|
1135
|
+
* @returns `{ items, nextCursor }` — `nextCursor` is `null` when there are no more pages.
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* ```ts
|
|
1139
|
+
* const { items } = await auth.invite.list(ctx, {
|
|
1140
|
+
* where: { groupId, status: "pending" },
|
|
1141
|
+
* orderBy: "_creationTime",
|
|
1142
|
+
* order: "desc",
|
|
1143
|
+
* });
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
list: (ctx: ComponentReadCtx, opts?: {
|
|
1147
|
+
where?: {
|
|
1148
|
+
tokenHash?: string;
|
|
1149
|
+
groupId?: string;
|
|
1150
|
+
status?: "pending" | "accepted" | "revoked" | "expired";
|
|
1151
|
+
email?: string;
|
|
1152
|
+
invitedByUserId?: string;
|
|
1153
|
+
roleId?: string;
|
|
1154
|
+
acceptedByUserId?: string;
|
|
1155
|
+
};
|
|
1156
|
+
limit?: number;
|
|
1157
|
+
cursor?: string | null;
|
|
1158
|
+
orderBy?: "_creationTime" | "status" | "email" | "expiresTime" | "acceptedTime";
|
|
1159
|
+
order?: "asc" | "desc";
|
|
1160
|
+
}) => Promise<any>;
|
|
1161
|
+
/**
|
|
1162
|
+
* Accept an invite by ID. Optionally specify who accepted it.
|
|
1163
|
+
*
|
|
1164
|
+
* Transitions the invite's status to `"accepted"` and optionally
|
|
1165
|
+
* records the accepting user. Unlike `invite.token.accept`, this
|
|
1166
|
+
* method does not automatically create a group membership — use it
|
|
1167
|
+
* for admin-driven invite acceptance flows.
|
|
1168
|
+
*
|
|
1169
|
+
* @param ctx - Convex mutation context.
|
|
1170
|
+
* @param inviteId - The invite's document ID.
|
|
1171
|
+
* @param acceptedByUserId - The user who accepted the invite (optional).
|
|
1172
|
+
* @returns `{ ok: true, inviteId, acceptedByUserId }`.
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```ts
|
|
1176
|
+
* await auth.invite.accept(ctx, inviteId, userId);
|
|
1177
|
+
* ```
|
|
1178
|
+
*/
|
|
1179
|
+
accept: (ctx: ComponentCtx, inviteId: string, acceptedByUserId?: string) => Promise<{
|
|
1180
|
+
ok: true;
|
|
1181
|
+
inviteId: string;
|
|
1182
|
+
acceptedByUserId: string | null;
|
|
1183
|
+
}>;
|
|
1184
|
+
/**
|
|
1185
|
+
* Revoke a pending invite. Sets its status to `"revoked"`.
|
|
1186
|
+
*
|
|
1187
|
+
* Once revoked, the invite's token can no longer be used to accept
|
|
1188
|
+
* the invitation. This is a permanent status change.
|
|
1189
|
+
*
|
|
1190
|
+
* @param ctx - Convex mutation context.
|
|
1191
|
+
* @param inviteId - The invite's document ID.
|
|
1192
|
+
* @returns `{ ok: true, inviteId }`.
|
|
1193
|
+
*
|
|
1194
|
+
* @example
|
|
1195
|
+
* ```ts
|
|
1196
|
+
* await auth.invite.revoke(ctx, inviteId);
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
1199
|
+
revoke: (ctx: ComponentCtx, inviteId: string) => Promise<{
|
|
1200
|
+
ok: true;
|
|
1201
|
+
inviteId: string;
|
|
1202
|
+
}>;
|
|
1203
|
+
};
|
|
1204
|
+
key: {
|
|
1205
|
+
/**
|
|
1206
|
+
* Create an API key for programmatic access. The returned `secret`
|
|
1207
|
+
* (prefixed `sk_`) is shown only once — it is stored as a hash.
|
|
1208
|
+
*
|
|
1209
|
+
* @param ctx - Convex mutation context.
|
|
1210
|
+
* @param opts.userId - Owner of the key.
|
|
1211
|
+
* @param opts.name - Human-readable name (e.g. `"CI Pipeline"`).
|
|
1212
|
+
* @param opts.scopes - Array of `{ resource, actions }` permission scopes.
|
|
1213
|
+
* @param opts.rateLimit - Optional per-key rate limit `{ maxRequests, windowMs }`.
|
|
1214
|
+
* @param opts.expiresAt - Optional expiration timestamp (ms since epoch).
|
|
1215
|
+
* @param opts.metadata - Arbitrary app-specific metadata.
|
|
1216
|
+
* @returns `{ ok: true, keyId, secret }`. Store `secret` securely — it cannot be retrieved later.
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```ts
|
|
1220
|
+
* const { secret } = await auth.key.create(ctx, {
|
|
1221
|
+
* userId,
|
|
1222
|
+
* name: "CI Pipeline",
|
|
1223
|
+
* scopes: [{ resource: "data", actions: ["read"] }],
|
|
1224
|
+
* });
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
create: (ctx: ComponentCtx, opts: {
|
|
1228
|
+
userId: string;
|
|
1229
|
+
name: string;
|
|
1230
|
+
scopes: KeyScope[];
|
|
1231
|
+
rateLimit?: {
|
|
1232
|
+
maxRequests: number;
|
|
1233
|
+
windowMs: number;
|
|
1234
|
+
};
|
|
1235
|
+
expiresAt?: number;
|
|
1236
|
+
metadata?: Record<string, unknown>;
|
|
1237
|
+
}) => Promise<{
|
|
1238
|
+
ok: true;
|
|
1239
|
+
keyId: string;
|
|
1240
|
+
secret: string;
|
|
1241
|
+
}>;
|
|
1242
|
+
/**
|
|
1243
|
+
* Verify an API key and return the owner's identity and scopes.
|
|
1244
|
+
*
|
|
1245
|
+
* Checks the key against the database, enforces expiration and rate
|
|
1246
|
+
* limits, and returns a `ScopeChecker` for permission evaluation.
|
|
1247
|
+
*
|
|
1248
|
+
* @param ctx - Convex mutation context (updates `lastUsedAt` and rate limit state).
|
|
1249
|
+
* @param rawKey - The raw `sk_*` key string.
|
|
1250
|
+
* @returns On success: `{ ok: true, userId, keyId, scopes }` where `scopes.can(resource, action)` checks permissions.
|
|
1251
|
+
* On failure: `{ ok: false, code }` with one of:
|
|
1252
|
+
* - `"INVALID_API_KEY"` — key not found.
|
|
1253
|
+
* - `"API_KEY_REVOKED"` — key was revoked.
|
|
1254
|
+
* - `"API_KEY_EXPIRED"` — key past its `expiresAt`.
|
|
1255
|
+
* - `"API_KEY_RATE_LIMITED"` — rate limit exceeded.
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* const result = await auth.key.verify(ctx, rawKey);
|
|
1260
|
+
* if (!result.ok) return { ok: false, code: result.code };
|
|
1261
|
+
* const canRead = result.scopes.can("data", "read");
|
|
1262
|
+
* ```
|
|
1263
|
+
*/
|
|
1264
|
+
verify: (ctx: ComponentCtx, rawKey: string) => Promise<{
|
|
1265
|
+
ok: true;
|
|
1266
|
+
userId: string;
|
|
1267
|
+
keyId: string;
|
|
1268
|
+
scopes: ScopeChecker;
|
|
1269
|
+
} | {
|
|
1270
|
+
ok: false;
|
|
1271
|
+
code: "INVALID_API_KEY" | "API_KEY_REVOKED" | "API_KEY_EXPIRED" | "API_KEY_RATE_LIMITED";
|
|
1272
|
+
}>;
|
|
1273
|
+
/**
|
|
1274
|
+
* List API keys with optional filtering by user, revocation status, name,
|
|
1275
|
+
* or prefix. Results are paginated. Does not expose raw key secrets.
|
|
1276
|
+
*
|
|
1277
|
+
* @param ctx - Convex query or mutation context.
|
|
1278
|
+
* @param opts.where - Filter criteria (all optional, combined with AND).
|
|
1279
|
+
* @param opts.limit - Max items per page (default 50, max 100).
|
|
1280
|
+
* @param opts.cursor - Cursor from a previous `nextCursor` for pagination.
|
|
1281
|
+
* @param opts.orderBy - Sort field: `"_creationTime"`, `"name"`, `"lastUsedAt"`, `"expiresAt"`, or `"revoked"`.
|
|
1282
|
+
* @param opts.order - Sort direction: `"asc"` or `"desc"`.
|
|
1283
|
+
* @returns `{ items, nextCursor }` — `nextCursor` is `null` when no more pages.
|
|
1284
|
+
*
|
|
1285
|
+
* @example
|
|
1286
|
+
* ```ts
|
|
1287
|
+
* const { items } = await auth.key.list(ctx, {
|
|
1288
|
+
* where: { userId, revoked: false },
|
|
1289
|
+
* orderBy: "lastUsedAt",
|
|
1290
|
+
* order: "desc",
|
|
1291
|
+
* });
|
|
1292
|
+
* ```
|
|
1293
|
+
*/
|
|
1294
|
+
list: (ctx: ComponentReadCtx, opts?: {
|
|
1295
|
+
where?: {
|
|
1296
|
+
userId?: string;
|
|
1297
|
+
revoked?: boolean;
|
|
1298
|
+
name?: string;
|
|
1299
|
+
prefix?: string;
|
|
1300
|
+
};
|
|
1301
|
+
limit?: number;
|
|
1302
|
+
cursor?: string | null;
|
|
1303
|
+
orderBy?: "_creationTime" | "name" | "lastUsedAt" | "expiresAt" | "revoked";
|
|
1304
|
+
order?: "asc" | "desc";
|
|
1305
|
+
}) => Promise<any>;
|
|
1306
|
+
/**
|
|
1307
|
+
* Fetch an API key record by ID. Does not expose the raw key secret.
|
|
1308
|
+
*
|
|
1309
|
+
* Returns the key document including metadata, scopes, rate limit
|
|
1310
|
+
* configuration, and revocation status. The raw secret is never
|
|
1311
|
+
* stored or returned — only the hashed key and display prefix.
|
|
1312
|
+
*
|
|
1313
|
+
* @param ctx - Convex query or mutation context.
|
|
1314
|
+
* @param keyId - The API key's document ID.
|
|
1315
|
+
* @returns `{ ok: true, key }` with the key document, or `{ ok: false }` if not found.
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
* ```ts
|
|
1319
|
+
* const result = await auth.key.get(ctx, keyId);
|
|
1320
|
+
* if (!result.ok) throw new Error("Key not found");
|
|
1321
|
+
* console.log(result.key.name, result.key.prefix);
|
|
1322
|
+
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
get: (ctx: ComponentReadCtx, keyId: string) => Promise<{
|
|
1325
|
+
ok: true;
|
|
1326
|
+
key: KeyDoc;
|
|
1327
|
+
} | {
|
|
1328
|
+
ok: false;
|
|
1329
|
+
}>;
|
|
1330
|
+
/**
|
|
1331
|
+
* Update a key's name, scopes, or rate limit.
|
|
1332
|
+
*
|
|
1333
|
+
* Patches the specified fields on the API key document. Only the
|
|
1334
|
+
* provided fields are changed — omitted fields remain unchanged.
|
|
1335
|
+
*
|
|
1336
|
+
* @param ctx - Convex mutation context.
|
|
1337
|
+
* @param keyId - The API key's document ID.
|
|
1338
|
+
* @param data - Fields to merge into the key document.
|
|
1339
|
+
* @returns `{ ok: true, keyId }`.
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```ts
|
|
1343
|
+
* await auth.key.update(ctx, keyId, {
|
|
1344
|
+
* name: "CI Pipeline (updated)",
|
|
1345
|
+
* scopes: [{ resource: "data", actions: ["read", "write"] }],
|
|
1346
|
+
* });
|
|
1347
|
+
* ```
|
|
1348
|
+
*/
|
|
1349
|
+
update: (ctx: ComponentCtx, keyId: string, data: {
|
|
1350
|
+
name?: string;
|
|
1351
|
+
scopes?: KeyScope[];
|
|
1352
|
+
rateLimit?: {
|
|
1353
|
+
maxRequests: number;
|
|
1354
|
+
windowMs: number;
|
|
1355
|
+
};
|
|
1356
|
+
}) => Promise<{
|
|
1357
|
+
ok: true;
|
|
1358
|
+
keyId: string;
|
|
1359
|
+
}>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Soft-delete: set `revoked: true`. The key can no longer be verified.
|
|
1362
|
+
*
|
|
1363
|
+
* After revocation, any subsequent calls to `auth.key.verify` with
|
|
1364
|
+
* this key will return `{ ok: false, code: "API_KEY_REVOKED" }`.
|
|
1365
|
+
* The key record is preserved for audit purposes.
|
|
1366
|
+
*
|
|
1367
|
+
* @param ctx - Convex mutation context.
|
|
1368
|
+
* @param keyId - The API key's document ID.
|
|
1369
|
+
* @returns `{ ok: true, keyId }`.
|
|
1370
|
+
*
|
|
1371
|
+
* @example
|
|
1372
|
+
* ```ts
|
|
1373
|
+
* await auth.key.revoke(ctx, keyId);
|
|
1374
|
+
* ```
|
|
1375
|
+
*/
|
|
1376
|
+
revoke: (ctx: ComponentCtx, keyId: string) => Promise<{
|
|
1377
|
+
ok: true;
|
|
1378
|
+
keyId: string;
|
|
1379
|
+
}>;
|
|
1380
|
+
/**
|
|
1381
|
+
* Hard-delete: permanently remove the key record.
|
|
1382
|
+
*
|
|
1383
|
+
* Unlike `revoke`, this permanently removes the key document from
|
|
1384
|
+
* the database. Use this when you need to fully clean up a key
|
|
1385
|
+
* rather than preserving it for audit history.
|
|
1386
|
+
*
|
|
1387
|
+
* @param ctx - Convex mutation context.
|
|
1388
|
+
* @param keyId - The API key's document ID.
|
|
1389
|
+
* @returns `{ ok: true, keyId }`.
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* ```ts
|
|
1393
|
+
* await auth.key.delete(ctx, keyId);
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
delete: (ctx: ComponentCtx, keyId: string) => Promise<{
|
|
1397
|
+
ok: true;
|
|
1398
|
+
keyId: string;
|
|
1399
|
+
}>;
|
|
1400
|
+
/**
|
|
1401
|
+
* Rotate a key: revokes the old key and creates a new one with the
|
|
1402
|
+
* same user, scopes, and rate limit. Returns the new `keyId` and `secret`.
|
|
1403
|
+
* Fails with `{ ok: false }` if the key is already revoked.
|
|
1404
|
+
*
|
|
1405
|
+
* @param ctx - Convex mutation context.
|
|
1406
|
+
* @param keyId - The existing API key's document ID to rotate.
|
|
1407
|
+
* @param opts.name - Optional new name for the rotated key (defaults to the old name).
|
|
1408
|
+
* @param opts.expiresAt - Optional new expiration timestamp in ms since epoch.
|
|
1409
|
+
* @returns `{ ok: true, keyId, secret }` with the new key, or `{ ok: false, code }` on failure.
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```ts
|
|
1413
|
+
* const result = await auth.key.rotate(ctx, oldKeyId, {
|
|
1414
|
+
* expiresAt: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
1415
|
+
* });
|
|
1416
|
+
* if (result.ok) {
|
|
1417
|
+
* // Store result.secret securely — shown only once
|
|
1418
|
+
* }
|
|
1419
|
+
* ```
|
|
1420
|
+
*/
|
|
1421
|
+
rotate: (ctx: ComponentCtx, keyId: string, opts?: {
|
|
1422
|
+
name?: string;
|
|
1423
|
+
expiresAt?: number;
|
|
1424
|
+
}) => Promise<{
|
|
1425
|
+
ok: true;
|
|
1426
|
+
keyId: string;
|
|
1427
|
+
secret: string;
|
|
1428
|
+
} | {
|
|
1429
|
+
ok: false;
|
|
1430
|
+
code: "INVALID_PARAMETERS" | "API_KEY_REVOKED";
|
|
1431
|
+
}>;
|
|
1432
|
+
};
|
|
1433
|
+
};
|
|
1434
|
+
//#endregion
|
|
1435
|
+
export { createCoreDomains };
|
|
1436
|
+
//# sourceMappingURL=core.d.ts.map
|