@robelest/convex-auth 0.0.4-preview.18 → 0.0.4-preview.19
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 +6 -3
- package/dist/authorization/index.d.ts +46 -0
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +46 -0
- package/dist/authorization/index.js.map +1 -1
- package/dist/bin.cjs +21 -13
- 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 -16
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +67 -565
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +40 -12
- 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 +1306 -1344
- 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 -2
- package/dist/component/model.d.ts +80 -80
- package/dist/component/model.d.ts.map +1 -1
- package/dist/component/model.js +5 -1
- package/dist/component/model.js.map +1 -1
- package/dist/component/providers/credentials.d.ts +3 -2
- package/dist/component/providers/credentials.d.ts.map +1 -1
- package/dist/component/providers/email.d.ts +30 -0
- package/dist/component/providers/email.d.ts.map +1 -1
- package/dist/component/providers/phone.d.ts +28 -0
- package/dist/component/providers/phone.d.ts.map +1 -1
- 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 +22 -7
- package/dist/component/public.js +21 -6
- package/dist/component/schema.d.ts +288 -288
- package/dist/component/server/auth.d.ts +212 -25
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +68 -4
- 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} +2 -2
- package/dist/component/server/config.js.map +1 -0
- package/dist/component/server/{domains/core.js → core.js} +107 -88
- package/dist/component/server/core.js.map +1 -0
- package/dist/component/server/{provider.js → crypto.js} +3 -3
- package/dist/component/server/crypto.js.map +1 -0
- package/dist/component/server/device.js +1 -1
- package/dist/component/server/device.js.map +1 -1
- package/dist/component/server/enterprise/config.js +46 -0
- package/dist/component/server/enterprise/config.js.map +1 -0
- package/dist/component/server/{domains/sso.js → enterprise/domain.js} +6 -5
- 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.js.map +1 -1
- package/dist/component/server/http.js +2 -1
- package/dist/component/server/http.js.map +1 -1
- package/dist/component/server/identity.js +1 -1
- package/dist/component/server/identity.js.map +1 -1
- package/dist/component/server/{ratelimit.js → limits.js} +3 -3
- package/dist/component/server/limits.js.map +1 -0
- package/dist/component/server/mutations/account.js +3 -3
- package/dist/component/server/mutations/account.js.map +1 -1
- package/dist/component/server/mutations/code.js +2 -2
- package/dist/component/server/mutations/code.js.map +1 -1
- package/dist/component/server/mutations/invalidate.js +1 -1
- package/dist/component/server/mutations/invalidate.js.map +1 -1
- package/dist/component/server/mutations/oauth.js +5 -3
- package/dist/component/server/mutations/oauth.js.map +1 -1
- package/dist/component/server/mutations/refresh.js +1 -1
- package/dist/component/server/mutations/refresh.js.map +1 -1
- package/dist/component/server/mutations/register.js +3 -3
- package/dist/component/server/mutations/register.js.map +1 -1
- package/dist/component/server/mutations/retrieve.js +4 -4
- package/dist/component/server/mutations/retrieve.js.map +1 -1
- package/dist/component/server/mutations/signature.js +2 -2
- package/dist/component/server/mutations/signature.js.map +1 -1
- package/dist/component/server/mutations/signin.js +1 -1
- package/dist/component/server/mutations/signin.js.map +1 -1
- package/dist/component/server/mutations/signout.js +1 -1
- package/dist/component/server/mutations/signout.js.map +1 -1
- 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 +80 -10
- package/dist/component/server/mutations/store.js.map +1 -1
- package/dist/component/server/mutations/verifier.js +1 -1
- package/dist/component/server/mutations/verifier.js.map +1 -1
- package/dist/component/server/mutations/verify.js +4 -3
- package/dist/component/server/mutations/verify.js.map +1 -1
- package/dist/component/server/oauth.js +1 -1
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +2 -1
- package/dist/component/server/passkey.js.map +1 -1
- package/dist/component/server/redirects.js +1 -1
- package/dist/component/server/redirects.js.map +1 -1
- package/dist/component/server/refresh.js +1 -1
- package/dist/component/server/refresh.js.map +1 -1
- package/dist/component/server/{factory.d.ts → runtime.d.ts} +2 -2
- 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/component/server/signin.js +2 -1
- package/dist/component/server/signin.js.map +1 -1
- package/dist/component/server/totp.js +2 -1
- package/dist/component/server/totp.js.map +1 -1
- package/dist/component/server/types.d.ts +225 -41
- package/dist/component/server/types.d.ts.map +1 -1
- package/dist/component/server/types.js.map +1 -1
- package/dist/component/server/users.js +1 -1
- package/dist/component/server/users.js.map +1 -1
- package/dist/component/server/utils.js +1 -1
- 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/credentials.d.ts +5 -2
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +2 -0
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/email.d.ts +30 -0
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +24 -0
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/phone.d.ts +28 -0
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +22 -0
- package/dist/providers/phone.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 +218 -28
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +68 -4
- package/dist/server/auth.js.map +1 -1
- package/dist/server/{fx.d.ts → authError.d.ts} +25 -15
- 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/{providers.js → config.js} +2 -2
- package/dist/server/config.js.map +1 -0
- package/dist/server/core.d.ts +1436 -0
- package/dist/server/core.d.ts.map +1 -0
- package/dist/server/{domains/core.js → core.js} +107 -88
- package/dist/server/core.js.map +1 -0
- package/dist/server/{provider.d.ts → crypto.d.ts} +2 -2
- package/dist/server/crypto.d.ts.map +1 -0
- package/dist/server/{provider.js → crypto.js} +3 -3
- package/dist/{component/server/provider.js.map → server/crypto.js.map} +1 -1
- package/dist/server/device.js +1 -1
- package/dist/server/device.js.map +1 -1
- package/dist/server/enterprise/config.js +46 -0
- package/dist/server/enterprise/config.js.map +1 -0
- package/dist/server/{domains/sso.d.ts → enterprise/domain.d.ts} +4 -4
- package/dist/server/enterprise/domain.d.ts.map +1 -0
- package/dist/server/{domains/sso.js → enterprise/domain.js} +6 -5
- 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.js +248 -0
- package/dist/server/enterprise/oidc.js.map +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/{enterpriseValidators.js → enterprise/validators.js} +2 -2
- package/dist/server/enterprise/validators.js.map +1 -0
- package/dist/server/errors.d.ts +2 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +2 -0
- package/dist/server/errors.js.map +1 -1
- package/dist/server/http.d.ts +2 -2
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +2 -1
- package/dist/server/http.js.map +1 -1
- package/dist/server/identity.js +1 -1
- package/dist/server/identity.js.map +1 -1
- package/dist/server/index.d.ts +4 -705
- package/dist/server/index.js +4 -1367
- package/dist/server/limits.d.ts +1 -0
- package/dist/server/{ratelimit.js → limits.js} +3 -3
- 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 +8 -8
- package/dist/server/mutations/account.js +3 -3
- package/dist/server/mutations/account.js.map +1 -1
- package/dist/server/mutations/code.d.ts +13 -13
- package/dist/server/mutations/code.js +2 -2
- package/dist/server/mutations/code.js.map +1 -1
- package/dist/server/mutations/index.d.ts +8 -312
- package/dist/server/mutations/index.js +14 -84
- package/dist/server/mutations/invalidate.d.ts +5 -5
- package/dist/server/mutations/invalidate.d.ts.map +1 -1
- package/dist/server/mutations/invalidate.js +1 -1
- package/dist/server/mutations/invalidate.js.map +1 -1
- package/dist/server/mutations/oauth.d.ts +9 -9
- package/dist/server/mutations/oauth.d.ts.map +1 -1
- package/dist/server/mutations/oauth.js +5 -3
- package/dist/server/mutations/oauth.js.map +1 -1
- package/dist/server/mutations/refresh.d.ts +4 -4
- package/dist/server/mutations/refresh.js +1 -1
- package/dist/server/mutations/refresh.js.map +1 -1
- package/dist/server/mutations/register.d.ts +10 -10
- package/dist/server/mutations/register.d.ts.map +1 -1
- package/dist/server/mutations/register.js +3 -3
- package/dist/server/mutations/register.js.map +1 -1
- package/dist/server/mutations/retrieve.d.ts +8 -10
- package/dist/server/mutations/retrieve.d.ts.map +1 -1
- package/dist/server/mutations/retrieve.js +5 -7
- package/dist/server/mutations/retrieve.js.map +1 -1
- package/dist/server/mutations/signature.d.ts +6 -6
- package/dist/server/mutations/signature.d.ts.map +1 -1
- package/dist/server/mutations/signature.js +2 -2
- package/dist/server/mutations/signature.js.map +1 -1
- package/dist/server/mutations/signin.d.ts +1 -1
- package/dist/server/mutations/signin.js +1 -1
- package/dist/server/mutations/signin.js.map +1 -1
- package/dist/server/mutations/signout.d.ts +1 -1
- package/dist/server/mutations/signout.js +1 -1
- package/dist/server/mutations/signout.js.map +1 -1
- 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 +303 -9
- package/dist/server/mutations/store.d.ts.map +1 -1
- package/dist/server/mutations/store.js +80 -10
- package/dist/server/mutations/store.js.map +1 -1
- package/dist/server/mutations/verifier.d.ts +1 -1
- package/dist/server/mutations/verifier.js +1 -1
- package/dist/server/mutations/verifier.js.map +1 -1
- package/dist/server/mutations/verify.d.ts +8 -8
- package/dist/server/mutations/verify.d.ts.map +1 -1
- package/dist/server/mutations/verify.js +4 -3
- package/dist/server/mutations/verify.js.map +1 -1
- package/dist/server/oauth.js +1 -1
- package/dist/server/oauth.js.map +1 -1
- package/dist/server/passkey.d.ts +2 -2
- package/dist/server/passkey.d.ts.map +1 -1
- package/dist/server/passkey.js +3 -2
- package/dist/server/passkey.js.map +1 -1
- package/dist/server/redirects.js +1 -1
- package/dist/server/redirects.js.map +1 -1
- package/dist/server/refresh.js +1 -1
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/{factory.d.ts → runtime.d.ts} +16 -16
- 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/signin.js +3 -2
- package/dist/server/signin.js.map +1 -1
- 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/totp.js +2 -1
- package/dist/server/totp.js.map +1 -1
- package/dist/server/types.d.ts +242 -42
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +12 -1
- package/dist/server/types.js.map +1 -1
- package/dist/server/users.js +1 -1
- package/dist/server/users.js.map +1 -1
- package/dist/server/utils.js +1 -1
- package/dist/server/utils.js.map +1 -1
- package/package.json +3 -4
- package/src/authorization/index.ts +46 -0
- package/src/cli/index.ts +38 -20
- 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 +133 -1267
- 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 +40 -12
- package/src/component/_generated/component.ts +1772 -1798
- package/src/component/model.ts +6 -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 +27 -5
- package/src/providers/credentials.ts +4 -5
- package/src/providers/email.ts +30 -0
- package/src/providers/phone.ts +28 -0
- package/src/server/auth.ts +282 -28
- package/src/server/authError.ts +44 -0
- package/src/server/core.ts +2095 -0
- package/src/server/{provider.ts → crypto.ts} +1 -1
- package/src/server/device.ts +1 -1
- package/src/server/enterprise/config.ts +51 -0
- package/src/server/{domains/sso.ts → enterprise/domain.ts} +4 -2
- 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/errors.ts +2 -0
- package/src/server/http.ts +3 -1
- package/src/server/identity.ts +1 -1
- package/src/server/index.ts +32 -2605
- package/src/server/{ratelimit.ts → limits.ts} +1 -1
- package/src/server/mounts.ts +948 -0
- package/src/server/mutations/account.ts +4 -4
- package/src/server/mutations/code.ts +3 -3
- package/src/server/mutations/index.ts +8 -148
- package/src/server/mutations/invalidate.ts +2 -2
- package/src/server/mutations/oauth.ts +8 -6
- package/src/server/mutations/refresh.ts +3 -3
- package/src/server/mutations/register.ts +3 -3
- package/src/server/mutations/retrieve.ts +4 -8
- package/src/server/mutations/signature.ts +3 -3
- package/src/server/mutations/signin.ts +2 -2
- package/src/server/mutations/signout.ts +2 -2
- package/src/server/mutations/store/refs.ts +10 -0
- package/src/server/mutations/store.ts +137 -9
- package/src/server/mutations/verifier.ts +2 -2
- package/src/server/mutations/verify.ts +5 -5
- package/src/server/oauth.ts +1 -1
- package/src/server/passkey.ts +3 -4
- package/src/server/redirects.ts +1 -1
- package/src/server/refresh.ts +1 -1
- package/src/server/runtime.ts +880 -0
- package/src/server/signin.ts +3 -1
- package/src/server/ssr.ts +1764 -0
- package/src/server/totp.ts +3 -1
- package/src/server/types.ts +254 -43
- package/src/server/users.ts +1 -1
- package/src/server/utils.ts +1 -1
- package/src/test.ts +25 -0
- package/dist/component/public/enterprise.d.ts +0 -54
- package/dist/component/public/enterprise.d.ts.map +0 -1
- package/dist/component/public/enterprise.js +0 -515
- package/dist/component/public/enterprise.js.map +0 -1
- package/dist/component/public/factors.d.ts +0 -52
- package/dist/component/public/factors.d.ts.map +0 -1
- package/dist/component/public/factors.js +0 -285
- package/dist/component/public/factors.js.map +0 -1
- package/dist/component/public/groups.d.ts +0 -124
- package/dist/component/public/groups.d.ts.map +0 -1
- package/dist/component/public/groups.js +0 -680
- package/dist/component/public/groups.js.map +0 -1
- package/dist/component/public/identity.d.ts +0 -93
- package/dist/component/public/identity.d.ts.map +0 -1
- package/dist/component/public/identity.js +0 -426
- package/dist/component/public/identity.js.map +0 -1
- package/dist/component/public/keys.d.ts +0 -41
- package/dist/component/public/keys.d.ts.map +0 -1
- package/dist/component/public/keys.js +0 -157
- package/dist/component/public/keys.js.map +0 -1
- package/dist/component/public/shared.d.ts +0 -26
- package/dist/component/public/shared.d.ts.map +0 -1
- package/dist/component/public/shared.js +0 -32
- package/dist/component/public/shared.js.map +0 -1
- package/dist/component/server/domains/core.js.map +0 -1
- package/dist/component/server/domains/sso.js.map +0 -1
- package/dist/component/server/factory.d.ts.map +0 -1
- package/dist/component/server/factory.js +0 -1134
- package/dist/component/server/factory.js.map +0 -1
- package/dist/component/server/fx.js +0 -66
- package/dist/component/server/fx.js.map +0 -1
- package/dist/component/server/mutations/index.js +0 -85
- package/dist/component/server/mutations/index.js.map +0 -1
- package/dist/component/server/providers.js.map +0 -1
- package/dist/component/server/ratelimit.js.map +0 -1
- package/dist/component/server/sso.js +0 -830
- package/dist/component/server/sso.js.map +0 -1
- package/dist/server/domains/core.d.ts +0 -449
- package/dist/server/domains/core.d.ts.map +0 -1
- package/dist/server/domains/core.js.map +0 -1
- package/dist/server/domains/sso.d.ts.map +0 -1
- package/dist/server/domains/sso.js.map +0 -1
- package/dist/server/enterpriseValidators.js.map +0 -1
- package/dist/server/factory.d.ts.map +0 -1
- package/dist/server/factory.js +0 -1134
- package/dist/server/factory.js.map +0 -1
- package/dist/server/fx.d.ts.map +0 -1
- package/dist/server/fx.js +0 -66
- package/dist/server/fx.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/mutations/index.d.ts.map +0 -1
- package/dist/server/mutations/index.js.map +0 -1
- package/dist/server/provider.d.ts.map +0 -1
- package/dist/server/provider.js.map +0 -1
- package/dist/server/providers.js.map +0 -1
- package/dist/server/ratelimit.js.map +0 -1
- package/dist/server/sso.js +0 -830
- package/dist/server/sso.js.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/component/public/enterprise.ts +0 -753
- package/src/component/public/factors.ts +0 -333
- package/src/component/public/groups.ts +0 -1066
- package/src/component/public/identity.ts +0 -569
- package/src/component/public/keys.ts +0 -209
- package/src/component/public/shared.ts +0 -119
- package/src/server/domains/core.ts +0 -1096
- package/src/server/factory.ts +0 -2181
- package/src/server/fx.ts +0 -152
- package/src/server/sso.ts +0 -1516
- package/src/server/version.ts +0 -2
- /package/dist/server/{enterpriseValidators.d.ts → config.d.ts} +0 -0
- /package/dist/server/{providers.d.ts → enterprise/config.d.ts} +0 -0
- /package/dist/server/{ratelimit.d.ts → enterprise/oidc.d.ts} +0 -0
- /package/dist/server/{sso.d.ts → enterprise/policy.d.ts} +0 -0
- /package/src/server/{providers.ts → config.ts} +0 -0
- /package/src/server/{enterpriseValidators.ts → enterprise/validators.ts} +0 -0
package/src/server/auth.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type { UserIdentity } from "convex/server";
|
|
|
8
8
|
import type { GenericId } from "convex/values";
|
|
9
9
|
|
|
10
10
|
import type { AuthApiRefs } from "../client/index";
|
|
11
|
-
import { Auth as AuthFactory } from "./
|
|
12
|
-
import { Fx } from "
|
|
13
|
-
import { AuthError } from "./
|
|
11
|
+
import { Auth as AuthFactory } from "./runtime";
|
|
12
|
+
import { Fx } from "@robelest/fx";
|
|
13
|
+
import { AuthError } from "./authError";
|
|
14
14
|
import type { Doc } from "./types";
|
|
15
15
|
import type {
|
|
16
16
|
AuthAuthorizationConfig,
|
|
@@ -84,6 +84,7 @@ type MemberApiWithAuthorization<
|
|
|
84
84
|
opts: {
|
|
85
85
|
userId: string;
|
|
86
86
|
groupId: string;
|
|
87
|
+
ancestry?: boolean;
|
|
87
88
|
roleIds?: AuthRoleId<TAuthorization>[];
|
|
88
89
|
grants?: AuthGrant<TAuthorization>[];
|
|
89
90
|
maxDepth?: number;
|
|
@@ -91,23 +92,22 @@ type MemberApiWithAuthorization<
|
|
|
91
92
|
) => ReturnType<ReturnType<typeof AuthFactory>["auth"]["member"]["resolve"]>;
|
|
92
93
|
};
|
|
93
94
|
|
|
94
|
-
type AccessApiWithAuthorization<
|
|
95
|
-
TAuthorization extends AuthAuthorizationConfig | undefined,
|
|
96
|
-
> = {
|
|
97
|
-
check: (
|
|
98
|
-
ctx: Parameters<
|
|
99
|
-
ReturnType<typeof AuthFactory>["auth"]["access"]["check"]
|
|
100
|
-
>[0],
|
|
101
|
-
opts: {
|
|
102
|
-
userId: string;
|
|
103
|
-
groupId: string;
|
|
104
|
-
grants: AuthGrant<TAuthorization>[];
|
|
105
|
-
maxDepth?: number;
|
|
106
|
-
},
|
|
107
|
-
) => ReturnType<ReturnType<typeof AuthFactory>["auth"]["access"]["check"]>;
|
|
108
|
-
};
|
|
109
95
|
|
|
110
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* The base auth API surface returned by {@link createAuth}.
|
|
98
|
+
*
|
|
99
|
+
* Provides core namespaces — `signIn`, `signOut`, `user`, `session`,
|
|
100
|
+
* `member`, `invite`, `group`, `key`, and `http` — that are
|
|
101
|
+
* always available regardless of which providers are configured.
|
|
102
|
+
* Enterprise namespaces (`sso`, `scim`) are added conditionally by
|
|
103
|
+
* {@link AuthApi} when an SSO provider is present.
|
|
104
|
+
*
|
|
105
|
+
* Use this type when you want to describe code that only depends on the
|
|
106
|
+
* standard auth surface and should not assume enterprise features exist.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam TAuthorization - The authorization config, used to narrow
|
|
109
|
+
* role IDs and grant strings on the `member` API.
|
|
110
|
+
*/
|
|
111
111
|
export type AuthApiBase<
|
|
112
112
|
TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
|
|
113
113
|
> = {
|
|
@@ -120,10 +120,100 @@ export type AuthApiBase<
|
|
|
120
120
|
account: ReturnType<typeof AuthFactory>["auth"]["account"];
|
|
121
121
|
group: ReturnType<typeof AuthFactory>["auth"]["group"];
|
|
122
122
|
member: MemberApiWithAuthorization<TAuthorization>;
|
|
123
|
-
access: AccessApiWithAuthorization<TAuthorization>;
|
|
124
123
|
invite: ReturnType<typeof AuthFactory>["auth"]["invite"];
|
|
125
124
|
key: ReturnType<typeof AuthFactory>["auth"]["key"];
|
|
126
125
|
http: ReturnType<typeof AuthFactory>["auth"]["http"];
|
|
126
|
+
/**
|
|
127
|
+
* Resolve the current user's auth context. Framework-agnostic — use
|
|
128
|
+
* this in fluent-convex middleware, custom wrappers, or anywhere you
|
|
129
|
+
* need the resolved `{ userId, user, groupId, role, grants }` object.
|
|
130
|
+
*
|
|
131
|
+
* Returns `null` when unauthenticated. Does not throw.
|
|
132
|
+
*
|
|
133
|
+
* @param ctx - Convex query, mutation, or action context.
|
|
134
|
+
* @returns The resolved auth context, or `null`.
|
|
135
|
+
*
|
|
136
|
+
* @example fluent-convex middleware
|
|
137
|
+
* ```ts
|
|
138
|
+
* const withAuth = convex.createMiddleware(async (ctx, next) => {
|
|
139
|
+
* return next({ ...ctx, auth: await auth.resolve(ctx) });
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example Direct usage in a handler
|
|
144
|
+
* ```ts
|
|
145
|
+
* const resolved = await auth.resolve(ctx);
|
|
146
|
+
* if (!resolved) return { ok: false, code: "NOT_SIGNED_IN" };
|
|
147
|
+
* const { userId, grants } = resolved;
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
resolve: (ctx: any) => Promise<AuthResolvedContext | null>;
|
|
151
|
+
/**
|
|
152
|
+
* Context enrichment for convex-helpers `customQuery` / `customMutation` /
|
|
153
|
+
* `customAction`.
|
|
154
|
+
*
|
|
155
|
+
* Resolves the current user's identity, active group, membership role,
|
|
156
|
+
* and grants, then attaches them to `ctx.auth`. Returns a `Customization`
|
|
157
|
+
* object compatible with convex-helpers' custom function builders.
|
|
158
|
+
*
|
|
159
|
+
* `ctx.auth` is `{ userId, user, groupId, role, grants }` when
|
|
160
|
+
* authenticated, `null` when unauthenticated. No throwing — your
|
|
161
|
+
* handler decides how to respond.
|
|
162
|
+
*
|
|
163
|
+
* @returns A convex-helpers `Customization` object.
|
|
164
|
+
*
|
|
165
|
+
* @example One-time setup in `convex/functions.ts`
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { query, mutation, action } from "./_generated/server";
|
|
168
|
+
* import { customQuery, customMutation, customAction } from "convex-helpers/server/customFunctions";
|
|
169
|
+
* import { auth } from "./auth";
|
|
170
|
+
*
|
|
171
|
+
* export const authQuery = customQuery(query, auth.ctx());
|
|
172
|
+
* export const authMutation = customMutation(mutation, auth.ctx());
|
|
173
|
+
* export const authAction = customAction(action, auth.ctx());
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Per-function usage
|
|
177
|
+
* ```ts
|
|
178
|
+
* import { authQuery } from "./functions";
|
|
179
|
+
*
|
|
180
|
+
* export const list = authQuery({
|
|
181
|
+
* args: { workspaceId: v.string() },
|
|
182
|
+
* handler: async (ctx, args) => {
|
|
183
|
+
* if (!ctx.auth) return [];
|
|
184
|
+
* const { userId, groupId, grants } = ctx.auth;
|
|
185
|
+
* // business logic
|
|
186
|
+
* },
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
ctx: () => {
|
|
191
|
+
args: Record<string, never>;
|
|
192
|
+
input: (ctx: any) => Promise<{
|
|
193
|
+
ctx: { auth: AuthResolvedContext | null };
|
|
194
|
+
args: Record<string, never>;
|
|
195
|
+
}>;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Resolved auth context injected into `ctx.auth` by `auth.ctx()`.
|
|
201
|
+
*
|
|
202
|
+
* - `null` when unauthenticated.
|
|
203
|
+
* - `groupId` is `null` when the user has no active group set.
|
|
204
|
+
* - `role` / `grants` are `null` / `[]` when no active group or no membership.
|
|
205
|
+
*/
|
|
206
|
+
export type AuthResolvedContext = {
|
|
207
|
+
/** The authenticated user's document ID. */
|
|
208
|
+
userId: string;
|
|
209
|
+
/** The authenticated user's full document. */
|
|
210
|
+
user: any;
|
|
211
|
+
/** The user's active group ID, or `null` if none set. */
|
|
212
|
+
groupId: string | null;
|
|
213
|
+
/** The user's primary role in the active group, or `null`. */
|
|
214
|
+
role: string | null;
|
|
215
|
+
/** Resolved grant strings from the user's role definitions. */
|
|
216
|
+
grants: string[];
|
|
127
217
|
};
|
|
128
218
|
|
|
129
219
|
type InternalSsoApi = ReturnType<typeof AuthFactory>["auth"]["sso"];
|
|
@@ -208,7 +298,21 @@ type PublicScimApi = {
|
|
|
208
298
|
admin: Omit<InternalSsoApi["scim"], "getConfigByToken" | "identity">;
|
|
209
299
|
};
|
|
210
300
|
|
|
211
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Extended auth API that includes enterprise SSO and SCIM namespaces.
|
|
303
|
+
*
|
|
304
|
+
* This type is the union of {@link AuthApiBase} plus `sso` (SSO connection
|
|
305
|
+
* management, OIDC/SAML, domain verification, policies, audit, webhooks)
|
|
306
|
+
* and `scim` (SCIM provisioning configuration). It is returned by
|
|
307
|
+
* {@link createAuth} only when `new SSO()` is included in the providers
|
|
308
|
+
* array; otherwise the narrower {@link AuthApiBase} is returned instead.
|
|
309
|
+
* Attempting to access `auth.sso` or `auth.scim` without an SSO provider
|
|
310
|
+
* produces a compile-time error because the return type narrows back to
|
|
311
|
+
* {@link AuthApiBase}.
|
|
312
|
+
*
|
|
313
|
+
* @typeParam TAuthorization - The authorization config, forwarded to
|
|
314
|
+
* {@link AuthApiBase} for typed role IDs and grant strings.
|
|
315
|
+
*/
|
|
212
316
|
export type AuthApi<
|
|
213
317
|
TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
|
|
214
318
|
> = AuthApiBase<TAuthorization> & {
|
|
@@ -217,9 +321,19 @@ export type AuthApi<
|
|
|
217
321
|
};
|
|
218
322
|
|
|
219
323
|
/**
|
|
220
|
-
* The return type of
|
|
221
|
-
*
|
|
222
|
-
*
|
|
324
|
+
* The return type of {@link createAuth}.
|
|
325
|
+
*
|
|
326
|
+
* Resolves to {@link AuthApi} (with `sso` and `scim` namespaces) when
|
|
327
|
+
* `new SSO()` is present in the providers array, or to the narrower
|
|
328
|
+
* {@link AuthApiBase} otherwise. This conditional type ensures that
|
|
329
|
+
* enterprise-only APIs are only accessible when the SSO provider is
|
|
330
|
+
* configured, producing a compile-time error if you try to access
|
|
331
|
+
* `auth.sso` without it.
|
|
332
|
+
* This lets application code keep a single `createAuth()` call while still
|
|
333
|
+
* getting provider-aware typing on the resulting API object.
|
|
334
|
+
*
|
|
335
|
+
* @typeParam P - The tuple of provider configs passed to `createAuth`.
|
|
336
|
+
* @typeParam TAuthorization - Optional authorization config for typed roles/grants.
|
|
223
337
|
*/
|
|
224
338
|
export type ConvexAuthResult<
|
|
225
339
|
P extends AuthProviderConfig[],
|
|
@@ -240,9 +354,11 @@ export type ConvexAuthResult<
|
|
|
240
354
|
*
|
|
241
355
|
* // Frontend
|
|
242
356
|
* import type { auth } from "../convex/auth";
|
|
243
|
-
* import type { InferClientApi } from "@robelest/convex-auth/
|
|
357
|
+
* import type { InferClientApi } from "@robelest/convex-auth/server";
|
|
244
358
|
* const c = client<InferClientApi<typeof auth>>({ convex, api: api.auth });
|
|
245
359
|
* ```
|
|
360
|
+
*
|
|
361
|
+
* @typeParam T - A ConvexAuthResult to extract the client API from.
|
|
246
362
|
*/
|
|
247
363
|
export type InferClientApi<T> =
|
|
248
364
|
T extends ConvexAuthResult<infer P>
|
|
@@ -266,7 +382,58 @@ export type AuthLike = Pick<AuthApiBase, "user">;
|
|
|
266
382
|
* When `new SSO()` is included in providers, `auth.sso` and `auth.scim`
|
|
267
383
|
* are available on the returned object. Without it, those namespaces are
|
|
268
384
|
* absent and accessing them is a TypeScript compile error.
|
|
385
|
+
*
|
|
386
|
+
* @param component - The installed auth component reference from
|
|
387
|
+
* `components.auth` in your Convex app definition.
|
|
388
|
+
* @param config - Auth configuration including `providers` and optional
|
|
389
|
+
* `authorization`. All fields from {@link AuthConfig} are accepted
|
|
390
|
+
* except `component` (passed as the first argument).
|
|
391
|
+
* @returns A {@link ConvexAuthResult} object — either {@link AuthApi}
|
|
392
|
+
* (with `sso`/`scim`) or {@link AuthApiBase}, depending on whether
|
|
393
|
+
* an SSO provider is present.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* export const auth = createAuth(components.auth, {
|
|
398
|
+
* providers: [password(), google()],
|
|
399
|
+
* authorization: { roles },
|
|
400
|
+
* });
|
|
401
|
+
* ```
|
|
402
|
+
*
|
|
403
|
+
* @see {@link AuthCtx}
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
// ---------------------------------------------------------------------------
|
|
407
|
+
// Function builders — shared auth resolution logic
|
|
408
|
+
// ---------------------------------------------------------------------------
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Resolve auth context for the current user. Returns the enriched
|
|
412
|
+
* `ctx.auth` object or `null` when unauthenticated.
|
|
413
|
+
*
|
|
414
|
+
* Resolution flow:
|
|
415
|
+
* 1. `user.id(ctx)` → userId or null (exit early)
|
|
416
|
+
* 2. `user.get(ctx, userId)` → user doc (cached per-execution)
|
|
417
|
+
* 3. `user.getActiveGroup(ctx, { userId })` → groupId or null
|
|
418
|
+
* 4. If groupId → `member.resolve(ctx, { userId, groupId })` → role + grants
|
|
269
419
|
*/
|
|
420
|
+
async function resolveAuthContext(auth: any, ctx: any) {
|
|
421
|
+
const userId = await auth.user.id(ctx);
|
|
422
|
+
if (!userId) return null;
|
|
423
|
+
const user = await auth.user.get(ctx, userId);
|
|
424
|
+
const groupId = await auth.user.getActiveGroup(ctx, { userId });
|
|
425
|
+
let role: string | null = null;
|
|
426
|
+
let grants: string[] = [];
|
|
427
|
+
if (groupId) {
|
|
428
|
+
const resolved = await auth.member.resolve(ctx, { userId, groupId });
|
|
429
|
+
if (resolved.membership) {
|
|
430
|
+
role = resolved.roleIds[0] ?? null;
|
|
431
|
+
grants = resolved.grants;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return { userId, user, groupId, role, grants };
|
|
435
|
+
}
|
|
436
|
+
|
|
270
437
|
export function createAuth<
|
|
271
438
|
P extends AuthProviderConfig[],
|
|
272
439
|
TAuthorization extends AuthAuthorizationConfig | undefined = undefined,
|
|
@@ -450,7 +617,6 @@ export function createAuth<
|
|
|
450
617
|
account: authResult.auth.account,
|
|
451
618
|
group: authResult.auth.group,
|
|
452
619
|
member: authResult.auth.member,
|
|
453
|
-
access: authResult.auth.access,
|
|
454
620
|
invite: authResult.auth.invite,
|
|
455
621
|
key: authResult.auth.key,
|
|
456
622
|
sso: publicSso,
|
|
@@ -462,6 +628,16 @@ export function createAuth<
|
|
|
462
628
|
},
|
|
463
629
|
},
|
|
464
630
|
http: authResult.auth.http,
|
|
631
|
+
|
|
632
|
+
resolve: (ctx: any) => resolveAuthContext(authResult.auth, ctx),
|
|
633
|
+
|
|
634
|
+
ctx: () => ({
|
|
635
|
+
args: {},
|
|
636
|
+
input: async (ctx: any) => {
|
|
637
|
+
const authCtx = await resolveAuthContext(authResult.auth, ctx);
|
|
638
|
+
return { ctx: { auth: authCtx }, args: {} };
|
|
639
|
+
},
|
|
640
|
+
}),
|
|
465
641
|
} as unknown as ConvexAuthResult<P, TAuthorization>;
|
|
466
642
|
}
|
|
467
643
|
|
|
@@ -469,16 +645,49 @@ export function createAuth<
|
|
|
469
645
|
// AuthCtx — ctx enrichment for customQuery / customMutation
|
|
470
646
|
// ============================================================================
|
|
471
647
|
|
|
648
|
+
/** Canonical user document type exposed by Convex Auth. */
|
|
472
649
|
export type UserDoc = Doc<"User">;
|
|
473
650
|
|
|
651
|
+
/**
|
|
652
|
+
* Configuration for {@link AuthCtx} context enrichment.
|
|
653
|
+
*
|
|
654
|
+
* @typeParam TResolve - Extra fields returned from `resolve()` and merged into
|
|
655
|
+
* the resulting `ctx.auth` object.
|
|
656
|
+
*/
|
|
474
657
|
export type AuthCtxConfig<
|
|
475
658
|
TResolve extends Record<string, unknown> = Record<string, never>,
|
|
476
659
|
> = {
|
|
660
|
+
/** Allow unauthenticated callers and return `userId: null` / `user: null`. */
|
|
477
661
|
optional?: boolean;
|
|
662
|
+
/**
|
|
663
|
+
* Attach additional derived fields to the auth context after the user is resolved.
|
|
664
|
+
*/
|
|
478
665
|
resolve?: (ctx: any, user: UserDoc) => Promise<TResolve> | TResolve;
|
|
479
666
|
};
|
|
480
667
|
|
|
481
|
-
/**
|
|
668
|
+
/**
|
|
669
|
+
* Create a context enrichment for `customQuery` / `customMutation` — optional auth.
|
|
670
|
+
*
|
|
671
|
+
* When `optional: true` is set, unauthenticated requests are allowed.
|
|
672
|
+
* The enriched `ctx.auth` will have `userId: null` and `user: null`
|
|
673
|
+
* for unauthenticated callers.
|
|
674
|
+
*
|
|
675
|
+
* @param auth - The auth API object returned by {@link createAuth}.
|
|
676
|
+
* @param config - Configuration with `optional: true` and an optional
|
|
677
|
+
* `resolve` callback for attaching extra fields to the auth context.
|
|
678
|
+
* @returns An object with `args` and `input` compatible with Convex
|
|
679
|
+
* custom function builders.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* const authCtx = AuthCtx(auth, {
|
|
684
|
+
* optional: true,
|
|
685
|
+
* resolve: async (_ctx, user) => ({ plan: user?.extend?.plan ?? null }),
|
|
686
|
+
* });
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* @see {@link createAuth}
|
|
690
|
+
*/
|
|
482
691
|
export function AuthCtx<
|
|
483
692
|
TResolve extends Record<string, unknown> = Record<string, never>,
|
|
484
693
|
>(
|
|
@@ -501,7 +710,29 @@ export function AuthCtx<
|
|
|
501
710
|
args: {};
|
|
502
711
|
}>;
|
|
503
712
|
};
|
|
504
|
-
/**
|
|
713
|
+
/**
|
|
714
|
+
* Create a context enrichment for `customQuery` / `customMutation` — required auth (default).
|
|
715
|
+
*
|
|
716
|
+
* When `optional` is omitted or `false`, the inferred type is the authenticated
|
|
717
|
+
* auth shape. At runtime this helper still resolves instead of throwing, so if
|
|
718
|
+
* no user is signed in the returned `ctx.auth.userId` and `ctx.auth.user` are
|
|
719
|
+
* `null`.
|
|
720
|
+
*
|
|
721
|
+
* @param auth - The auth API object returned by {@link createAuth}.
|
|
722
|
+
* @param config - Optional configuration with a `resolve` callback
|
|
723
|
+
* for attaching extra fields to the auth context.
|
|
724
|
+
* @returns An object with `args` and `input` compatible with Convex
|
|
725
|
+
* custom function builders.
|
|
726
|
+
*
|
|
727
|
+
* @example
|
|
728
|
+
* ```ts
|
|
729
|
+
* const authCtx = AuthCtx(auth, {
|
|
730
|
+
* resolve: async (_ctx, user) => ({ email: user.email }),
|
|
731
|
+
* });
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* @see {@link createAuth}
|
|
735
|
+
*/
|
|
505
736
|
export function AuthCtx<
|
|
506
737
|
TResolve extends Record<string, unknown> = Record<string, never>,
|
|
507
738
|
>(
|
|
@@ -588,6 +819,29 @@ export function AuthCtx(auth: AuthLike, config?: AuthCtxConfig<any>) {
|
|
|
588
819
|
};
|
|
589
820
|
}
|
|
590
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Extract the resolved `auth` context type from an {@link AuthCtx} instance.
|
|
824
|
+
*
|
|
825
|
+
* Use this to type function parameters or variables that receive the
|
|
826
|
+
* enriched auth context produced by `AuthCtx`. The inferred type includes
|
|
827
|
+
* `userId`, `user`, `getUserIdentity`, and any additional fields added
|
|
828
|
+
* by the `resolve` callback. This is the generic utility for reusing the
|
|
829
|
+
* enriched auth shape without manually duplicating conditional auth types.
|
|
830
|
+
*
|
|
831
|
+
* @typeParam T - An `AuthCtx` return value (must have an `input` method
|
|
832
|
+
* that returns `{ ctx: { auth: ... } }`).
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* ```ts
|
|
836
|
+
* const authCtx = AuthCtx(auth, {
|
|
837
|
+
* resolve: async (ctx, user) => ({ orgId: user.orgId }),
|
|
838
|
+
* });
|
|
839
|
+
* type Auth = InferAuth<typeof authCtx>;
|
|
840
|
+
* // Auth = { userId: Id<"User">; user: UserDoc; getUserIdentity: ...; orgId: string }
|
|
841
|
+
* ```
|
|
842
|
+
*
|
|
843
|
+
* @see {@link createAuth}
|
|
844
|
+
*/
|
|
591
845
|
export type InferAuth<
|
|
592
846
|
T extends { input: (...args: any[]) => Promise<{ ctx: { auth: any } }> },
|
|
593
847
|
> = Awaited<ReturnType<T["input"]>>["ctx"]["auth"];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Cv } from "@robelest/fx/convex";
|
|
2
|
+
import type { ConvexError } from "convex/values";
|
|
3
|
+
|
|
4
|
+
import { AUTH_ERRORS } from "./errors";
|
|
5
|
+
import type { AuthErrorCode } from "./errors";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Typed error for the Fx error channel.
|
|
9
|
+
*
|
|
10
|
+
* Use with `Fx.fail(new AuthError("CODE"))` in pipelines.
|
|
11
|
+
* At Convex boundaries, {@link toConvexError} converts these to `ConvexError`.
|
|
12
|
+
*/
|
|
13
|
+
export class AuthError extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* Discriminant tag for error channel matching.
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
readonly _tag = "AuthError" as const;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
/**
|
|
22
|
+
* Machine-readable error code.
|
|
23
|
+
* @readonly
|
|
24
|
+
*/
|
|
25
|
+
readonly code: AuthErrorCode,
|
|
26
|
+
message?: string,
|
|
27
|
+
/**
|
|
28
|
+
* Optional structured context for diagnostics.
|
|
29
|
+
* @readonly
|
|
30
|
+
*/
|
|
31
|
+
readonly context?: Record<string, unknown>,
|
|
32
|
+
) {
|
|
33
|
+
super(message ?? AUTH_ERRORS[code]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Convert to the `ConvexError` shape the Convex runtime expects. */
|
|
37
|
+
toConvexError(): ConvexError<{ code: AuthErrorCode; message: string }> {
|
|
38
|
+
return Cv.error({
|
|
39
|
+
code: this.code,
|
|
40
|
+
message: this.message,
|
|
41
|
+
...this.context,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|