@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Fx } from "@robelest/fx";
|
|
2
|
+
import { ConvexError } from "convex/values";
|
|
3
|
+
|
|
4
|
+
//#region src/client/runtime/proxy.ts
|
|
5
|
+
const NETWORK_ERROR_PATTERN = /(network|fetch|load failed|failed to fetch)/i;
|
|
6
|
+
/** @internal */
|
|
7
|
+
function isTransientNetworkError(error) {
|
|
8
|
+
return error instanceof TypeError || error instanceof Error && NETWORK_ERROR_PATTERN.test(error.message || "");
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
function isRetriableProxyRefreshError(error) {
|
|
12
|
+
if (isTransientNetworkError(error)) return true;
|
|
13
|
+
if (!(error instanceof Error)) return false;
|
|
14
|
+
const statusMatch = error.message.match(/Proxy request failed:\s*(\d{3})/);
|
|
15
|
+
if (statusMatch === null) return false;
|
|
16
|
+
const statusCode = Number(statusMatch[1]);
|
|
17
|
+
return statusCode >= 500 && statusCode < 600;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
function createProxyHelpers(args) {
|
|
21
|
+
const { proxy } = args;
|
|
22
|
+
const resolveProxyUrl = () => {
|
|
23
|
+
const origin = typeof window !== "undefined" && typeof window.location?.origin === "string" ? window.location.origin : typeof location !== "undefined" && typeof location.origin === "string" ? location.origin : null;
|
|
24
|
+
if (origin !== null) return new URL(proxy, origin).toString();
|
|
25
|
+
return Fx.run(Fx.from({
|
|
26
|
+
ok: () => new URL(proxy).toString(),
|
|
27
|
+
err: () => proxy
|
|
28
|
+
}).pipe(Fx.recover((fallback) => Fx.succeed(fallback))));
|
|
29
|
+
};
|
|
30
|
+
const isAbsoluteUrl = (value) => {
|
|
31
|
+
return Fx.run(Fx.from({
|
|
32
|
+
ok: () => {
|
|
33
|
+
new URL(value);
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
err: () => false
|
|
37
|
+
}).pipe(Fx.recover((v) => Fx.succeed(v))));
|
|
38
|
+
};
|
|
39
|
+
const proxyFetch = async (body) => {
|
|
40
|
+
const proxyUrl = await resolveProxyUrl();
|
|
41
|
+
if (typeof window === "undefined" && !await isAbsoluteUrl(proxyUrl)) throw new Error(`Cannot call relative proxy URL \`${proxy}\` without a browser origin. Pass an absolute proxy URL for server runtimes.`);
|
|
42
|
+
const response = await fetch(proxyUrl, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
credentials: "include",
|
|
46
|
+
body: JSON.stringify(body)
|
|
47
|
+
});
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const errorBody = await Fx.run(Fx.from({
|
|
50
|
+
ok: () => response.json(),
|
|
51
|
+
err: () => ({})
|
|
52
|
+
}).pipe(Fx.recover((fallback) => Fx.succeed(fallback))));
|
|
53
|
+
if (typeof errorBody === "object" && errorBody !== null && "authError" in errorBody && typeof errorBody.authError === "object") throw new ConvexError(errorBody.authError);
|
|
54
|
+
throw new Error(errorBody.error ?? `Proxy request failed: ${response.status}`);
|
|
55
|
+
}
|
|
56
|
+
return Fx.run(Fx.from({
|
|
57
|
+
ok: () => response.json(),
|
|
58
|
+
err: () => /* @__PURE__ */ new Error("Proxy response was not valid JSON")
|
|
59
|
+
}).pipe(Fx.recover((e) => Fx.fatal(e))));
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
isAbsoluteUrl,
|
|
63
|
+
proxyFetch,
|
|
64
|
+
resolveProxyUrl
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createProxyHelpers, isRetriableProxyRefreshError, isTransientNetworkError };
|
|
70
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","names":[],"sources":["../../src/client/runtime/proxy.ts"],"sourcesContent":["import { Fx } from \"@robelest/fx\";\nimport { ConvexError, type Value } from \"convex/values\";\n\nconst NETWORK_ERROR_PATTERN = /(network|fetch|load failed|failed to fetch)/i;\n\n/** @internal */\nexport function isTransientNetworkError(error: unknown): boolean {\n return (\n error instanceof TypeError ||\n (error instanceof Error && NETWORK_ERROR_PATTERN.test(error.message || \"\"))\n );\n}\n\n/** @internal */\nexport function isRetriableProxyRefreshError(error: unknown): boolean {\n if (isTransientNetworkError(error)) {\n return true;\n }\n if (!(error instanceof Error)) {\n return false;\n }\n const statusMatch = error.message.match(/Proxy request failed:\\s*(\\d{3})/);\n if (statusMatch === null) {\n return false;\n }\n const statusCode = Number(statusMatch[1]);\n return statusCode >= 500 && statusCode < 600;\n}\n\n/** @internal */\nexport function createProxyHelpers(args: { proxy: string | undefined }) {\n const { proxy } = args;\n\n const resolveProxyUrl = () => {\n const origin =\n typeof window !== \"undefined\" &&\n typeof window.location?.origin === \"string\"\n ? window.location.origin\n : typeof location !== \"undefined\" && typeof location.origin === \"string\"\n ? location.origin\n : null;\n if (origin !== null) {\n return new URL(proxy!, origin).toString();\n }\n return Fx.run(\n Fx.from({\n ok: () => new URL(proxy!).toString(),\n err: () => proxy! as string,\n }).pipe(Fx.recover((fallback) => Fx.succeed(fallback))),\n );\n };\n\n const isAbsoluteUrl = (value: string) => {\n return Fx.run(\n Fx.from({\n ok: () => {\n new URL(value);\n return true;\n },\n err: () => false as const,\n }).pipe(Fx.recover((v) => Fx.succeed(v))),\n );\n };\n\n const proxyFetch = async (body: Record<string, unknown>) => {\n const proxyUrl = await resolveProxyUrl();\n if (typeof window === \"undefined\" && !(await isAbsoluteUrl(proxyUrl))) {\n throw new Error(\n `Cannot call relative proxy URL \\`${proxy!}\\` without a browser origin. ` +\n \"Pass an absolute proxy URL for server runtimes.\",\n );\n }\n\n const response = await fetch(proxyUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"include\",\n body: JSON.stringify(body),\n });\n if (!response.ok) {\n const errorBody = await Fx.run(\n Fx.from({\n ok: () => response.json() as Promise<Record<string, unknown>>,\n err: () => ({}) as Record<string, unknown>,\n }).pipe(Fx.recover((fallback) => Fx.succeed(fallback))),\n );\n if (\n typeof errorBody === \"object\" &&\n errorBody !== null &&\n \"authError\" in errorBody &&\n typeof (errorBody as Record<string, unknown>).authError === \"object\"\n ) {\n throw new ConvexError(\n (errorBody as Record<string, unknown>).authError as Value,\n );\n }\n throw new Error(\n ((errorBody as Record<string, unknown>).error as string) ??\n `Proxy request failed: ${response.status}`,\n );\n }\n return Fx.run(\n Fx.from({\n ok: () => response.json(),\n err: () => new Error(\"Proxy response was not valid JSON\"),\n }).pipe(Fx.recover((e) => Fx.fatal(e))),\n );\n };\n\n return { isAbsoluteUrl, proxyFetch, resolveProxyUrl };\n}\n"],"mappings":";;;;AAGA,MAAM,wBAAwB;;AAG9B,SAAgB,wBAAwB,OAAyB;AAC/D,QACE,iBAAiB,aAChB,iBAAiB,SAAS,sBAAsB,KAAK,MAAM,WAAW,GAAG;;;AAK9E,SAAgB,6BAA6B,OAAyB;AACpE,KAAI,wBAAwB,MAAM,CAChC,QAAO;AAET,KAAI,EAAE,iBAAiB,OACrB,QAAO;CAET,MAAM,cAAc,MAAM,QAAQ,MAAM,kCAAkC;AAC1E,KAAI,gBAAgB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ACD,OACE,OAAO,cAAc,YACrB,cAAc,QACd,eAAe,aACf,OAAQ,UAAsC,cAAc,SAE5D,OAAM,IAAI,YACP,UAAsC,UACxC;AAEH,SAAM,IAAI,MACN,UAAsC,SACtC,yBAAyB,SAAS,SACrC;;AAEH,SAAO,GAAG,IACR,GAAG,KAAK;GACN,UAAU,SAAS,MAAM;GACzB,2BAAW,IAAI,MAAM,oCAAoC;GAC1D,CAAC,CAAC,KAAK,GAAG,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CACxC;;AAGH,QAAO;EAAE;EAAe;EAAY;EAAiB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fx } from "@robelest/fx";
|
|
2
|
+
|
|
3
|
+
//#region src/client/runtime/storage.ts
|
|
4
|
+
/** @internal */
|
|
5
|
+
function createStorageHelpers(args) {
|
|
6
|
+
const { storage, key } = args;
|
|
7
|
+
const get = async (name) => {
|
|
8
|
+
if (!storage) return null;
|
|
9
|
+
return Fx.run(Fx.from({
|
|
10
|
+
ok: async () => await storage.getItem(key(name)) ?? null,
|
|
11
|
+
err: (e) => e
|
|
12
|
+
}).pipe(Fx.inspect((error) => Fx.sync(() => console.error(`[convex-auth] Failed to read ${name} from storage:`, error))), Fx.recover(() => Fx.succeed(null))));
|
|
13
|
+
};
|
|
14
|
+
const set = async (name, value) => {
|
|
15
|
+
if (!storage) return;
|
|
16
|
+
await Fx.run(Fx.from({
|
|
17
|
+
ok: () => storage.setItem(key(name), value),
|
|
18
|
+
err: (e) => e
|
|
19
|
+
}).pipe(Fx.inspect((error) => Fx.sync(() => console.error(`[convex-auth] Failed to write ${name} to storage:`, error))), Fx.recover(() => Fx.succeed(void 0))));
|
|
20
|
+
};
|
|
21
|
+
const remove = async (name) => {
|
|
22
|
+
if (!storage) return;
|
|
23
|
+
await Fx.run(Fx.from({
|
|
24
|
+
ok: () => storage.removeItem(key(name)),
|
|
25
|
+
err: (e) => e
|
|
26
|
+
}).pipe(Fx.inspect((error) => Fx.sync(() => console.error(`[convex-auth] Failed to remove ${name} from storage:`, error))), Fx.recover(() => Fx.succeed(void 0))));
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
get,
|
|
30
|
+
set,
|
|
31
|
+
remove
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createStorageHelpers };
|
|
37
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","names":[],"sources":["../../src/client/runtime/storage.ts"],"sourcesContent":["import { Fx } from \"@robelest/fx\";\n\nimport type { Storage } from \"../core/types\";\n\n/** @internal */\nexport function createStorageHelpers(args: {\n storage: Storage | null;\n key: (name: string) => string;\n}) {\n const { storage, key } = args;\n\n const get = async (name: string): Promise<string | null> => {\n if (!storage) {\n return null;\n }\n return Fx.run(\n Fx.from({\n ok: async () => (await storage.getItem(key(name))) ?? null,\n err: (e) => e,\n }).pipe(\n Fx.inspect((error) =>\n Fx.sync(() =>\n console.error(\n `[convex-auth] Failed to read ${name} from storage:`,\n error,\n ),\n ),\n ),\n Fx.recover(() => Fx.succeed(null)),\n ),\n );\n };\n\n const set = async (name: string, value: string): Promise<void> => {\n if (!storage) {\n return;\n }\n await Fx.run(\n Fx.from({\n ok: () => storage.setItem(key(name), value),\n err: (e) => e,\n }).pipe(\n Fx.inspect((error) =>\n Fx.sync(() =>\n console.error(\n `[convex-auth] Failed to write ${name} to storage:`,\n error,\n ),\n ),\n ),\n Fx.recover(() => Fx.succeed(undefined)),\n ),\n );\n };\n\n const remove = async (name: string): Promise<void> => {\n if (!storage) {\n return;\n }\n await Fx.run(\n Fx.from({\n ok: () => storage.removeItem(key(name)),\n err: (e) => e,\n }).pipe(\n Fx.inspect((error) =>\n Fx.sync(() =>\n console.error(\n `[convex-auth] Failed to remove ${name} from storage:`,\n error,\n ),\n ),\n ),\n Fx.recover(() => Fx.succeed(undefined)),\n ),\n );\n };\n\n return { get, set, remove };\n}\n"],"mappings":";;;;AAKA,SAAgB,qBAAqB,MAGlC;CACD,MAAM,EAAE,SAAS,QAAQ;CAEzB,MAAM,MAAM,OAAO,SAAyC;AAC1D,MAAI,CAAC,QACH,QAAO;AAET,SAAO,GAAG,IACR,GAAG,KAAK;GACN,IAAI,YAAa,MAAM,QAAQ,QAAQ,IAAI,KAAK,CAAC,IAAK;GACtD,MAAM,MAAM;GACb,CAAC,CAAC,KACD,GAAG,SAAS,UACV,GAAG,WACD,QAAQ,MACN,gCAAgC,KAAK,iBACrC,MACD,CACF,CACF,EACD,GAAG,cAAc,GAAG,QAAQ,KAAK,CAAC,CACnC,CACF;;CAGH,MAAM,MAAM,OAAO,MAAc,UAAiC;AAChE,MAAI,CAAC,QACH;AAEF,QAAM,GAAG,IACP,GAAG,KAAK;GACN,UAAU,QAAQ,QAAQ,IAAI,KAAK,EAAE,MAAM;GAC3C,MAAM,MAAM;GACb,CAAC,CAAC,KACD,GAAG,SAAS,UACV,GAAG,WACD,QAAQ,MACN,iCAAiC,KAAK,eACtC,MACD,CACF,CACF,EACD,GAAG,cAAc,GAAG,QAAQ,OAAU,CAAC,CACxC,CACF;;CAGH,MAAM,SAAS,OAAO,SAAgC;AACpD,MAAI,CAAC,QACH;AAEF,QAAM,GAAG,IACP,GAAG,KAAK;GACN,UAAU,QAAQ,WAAW,IAAI,KAAK,CAAC;GACvC,MAAM,MAAM;GACb,CAAC,CAAC,KACD,GAAG,SAAS,UACV,GAAG,WACD,QAAQ,MACN,kCAAkC,KAAK,iBACvC,MACD,CACF,CACF,EACD,GAAG,cAAc,GAAG,QAAQ,OAAU,CAAC,CACxC,CACF;;AAGH,QAAO;EAAE;EAAK;EAAK;EAAQ"}
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthAuthorizationConfig, AuthGrant, AuthProviderConfig, AuthRoleId, ConvexAuthConfig, Doc, HasDeviceProvider, HasPasskeyProvider, HasSSO, HasTotpProvider } from "./types.js";
|
|
2
|
-
import { AuthApiRefs } from "../client/
|
|
3
|
-
import
|
|
2
|
+
import { AuthApiRefs } from "../client/core/types.js";
|
|
3
|
+
import "../client/index.js";
|
|
4
|
+
import { Auth as Auth$1 } from "./runtime.js";
|
|
4
5
|
import { UserIdentity } from "convex/server";
|
|
5
6
|
import { GenericId } from "convex/values";
|
|
6
7
|
|
|
@@ -42,20 +43,27 @@ type MemberApiWithAuthorization<TAuthorization extends AuthAuthorizationConfig |
|
|
|
42
43
|
resolve: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["resolve"]>[0], opts: {
|
|
43
44
|
userId: string;
|
|
44
45
|
groupId: string;
|
|
46
|
+
ancestry?: boolean;
|
|
45
47
|
roleIds?: AuthRoleId<TAuthorization>[];
|
|
46
48
|
grants?: AuthGrant<TAuthorization>[];
|
|
47
49
|
maxDepth?: number;
|
|
48
50
|
}) => ReturnType<ReturnType<typeof Auth$1>["auth"]["member"]["resolve"]>;
|
|
49
51
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The base auth API surface returned by {@link createAuth}.
|
|
54
|
+
*
|
|
55
|
+
* Provides core namespaces — `signIn`, `signOut`, `user`, `session`,
|
|
56
|
+
* `member`, `invite`, `group`, `key`, and `http` — that are
|
|
57
|
+
* always available regardless of which providers are configured.
|
|
58
|
+
* Enterprise namespaces (`sso`, `scim`) are added conditionally by
|
|
59
|
+
* {@link AuthApi} when an SSO provider is present.
|
|
60
|
+
*
|
|
61
|
+
* Use this type when you want to describe code that only depends on the
|
|
62
|
+
* standard auth surface and should not assume enterprise features exist.
|
|
63
|
+
*
|
|
64
|
+
* @typeParam TAuthorization - The authorization config, used to narrow
|
|
65
|
+
* role IDs and grant strings on the `member` API.
|
|
66
|
+
*/
|
|
59
67
|
type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = undefined> = {
|
|
60
68
|
signIn: ReturnType<typeof Auth$1>["signIn"];
|
|
61
69
|
signOut: ReturnType<typeof Auth$1>["signOut"];
|
|
@@ -66,10 +74,96 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
66
74
|
account: ReturnType<typeof Auth$1>["auth"]["account"];
|
|
67
75
|
group: ReturnType<typeof Auth$1>["auth"]["group"];
|
|
68
76
|
member: MemberApiWithAuthorization<TAuthorization>;
|
|
69
|
-
access: AccessApiWithAuthorization<TAuthorization>;
|
|
70
77
|
invite: ReturnType<typeof Auth$1>["auth"]["invite"];
|
|
71
78
|
key: ReturnType<typeof Auth$1>["auth"]["key"];
|
|
72
79
|
http: ReturnType<typeof Auth$1>["auth"]["http"];
|
|
80
|
+
/**
|
|
81
|
+
* Resolve the current user's auth context. Framework-agnostic — use
|
|
82
|
+
* this in fluent-convex middleware, custom wrappers, or anywhere you
|
|
83
|
+
* need the resolved `{ userId, user, groupId, role, grants }` object.
|
|
84
|
+
*
|
|
85
|
+
* Returns `null` when unauthenticated. Does not throw.
|
|
86
|
+
*
|
|
87
|
+
* @param ctx - Convex query, mutation, or action context.
|
|
88
|
+
* @returns The resolved auth context, or `null`.
|
|
89
|
+
*
|
|
90
|
+
* @example fluent-convex middleware
|
|
91
|
+
* ```ts
|
|
92
|
+
* const withAuth = convex.createMiddleware(async (ctx, next) => {
|
|
93
|
+
* return next({ ...ctx, auth: await auth.resolve(ctx) });
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Direct usage in a handler
|
|
98
|
+
* ```ts
|
|
99
|
+
* const resolved = await auth.resolve(ctx);
|
|
100
|
+
* if (!resolved) return { ok: false, code: "NOT_SIGNED_IN" };
|
|
101
|
+
* const { userId, grants } = resolved;
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
resolve: (ctx: any) => Promise<AuthResolvedContext | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Context enrichment for convex-helpers `customQuery` / `customMutation` /
|
|
107
|
+
* `customAction`.
|
|
108
|
+
*
|
|
109
|
+
* Resolves the current user's identity, active group, membership role,
|
|
110
|
+
* and grants, then attaches them to `ctx.auth`. Returns a `Customization`
|
|
111
|
+
* object compatible with convex-helpers' custom function builders.
|
|
112
|
+
*
|
|
113
|
+
* `ctx.auth` is `{ userId, user, groupId, role, grants }` when
|
|
114
|
+
* authenticated, `null` when unauthenticated. No throwing — your
|
|
115
|
+
* handler decides how to respond.
|
|
116
|
+
*
|
|
117
|
+
* @returns A convex-helpers `Customization` object.
|
|
118
|
+
*
|
|
119
|
+
* @example One-time setup in `convex/functions.ts`
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { query, mutation, action } from "./_generated/server";
|
|
122
|
+
* import { customQuery, customMutation, customAction } from "convex-helpers/server/customFunctions";
|
|
123
|
+
* import { auth } from "./auth";
|
|
124
|
+
*
|
|
125
|
+
* export const authQuery = customQuery(query, auth.ctx());
|
|
126
|
+
* export const authMutation = customMutation(mutation, auth.ctx());
|
|
127
|
+
* export const authAction = customAction(action, auth.ctx());
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example Per-function usage
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { authQuery } from "./functions";
|
|
133
|
+
*
|
|
134
|
+
* export const list = authQuery({
|
|
135
|
+
* args: { workspaceId: v.string() },
|
|
136
|
+
* handler: async (ctx, args) => {
|
|
137
|
+
* if (!ctx.auth) return [];
|
|
138
|
+
* const { userId, groupId, grants } = ctx.auth;
|
|
139
|
+
* // business logic
|
|
140
|
+
* },
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
ctx: () => {
|
|
145
|
+
args: Record<string, never>;
|
|
146
|
+
input: (ctx: any) => Promise<{
|
|
147
|
+
ctx: {
|
|
148
|
+
auth: AuthResolvedContext | null;
|
|
149
|
+
};
|
|
150
|
+
args: Record<string, never>;
|
|
151
|
+
}>;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Resolved auth context injected into `ctx.auth` by `auth.ctx()`.
|
|
156
|
+
*
|
|
157
|
+
* - `null` when unauthenticated.
|
|
158
|
+
* - `groupId` is `null` when the user has no active group set.
|
|
159
|
+
* - `role` / `grants` are `null` / `[]` when no active group or no membership.
|
|
160
|
+
*/
|
|
161
|
+
type AuthResolvedContext = {
|
|
162
|
+
/** The authenticated user's document ID. */userId: string; /** The authenticated user's full document. */
|
|
163
|
+
user: any; /** The user's active group ID, or `null` if none set. */
|
|
164
|
+
groupId: string | null; /** The user's primary role in the active group, or `null`. */
|
|
165
|
+
role: string | null; /** Resolved grant strings from the user's role definitions. */
|
|
166
|
+
grants: string[];
|
|
73
167
|
};
|
|
74
168
|
type InternalSsoApi = ReturnType<typeof Auth$1>["auth"]["sso"];
|
|
75
169
|
type PublicSsoAdminApi = {
|
|
@@ -148,15 +242,39 @@ type PublicSsoApi = {
|
|
|
148
242
|
type PublicScimApi = {
|
|
149
243
|
admin: Omit<InternalSsoApi["scim"], "getConfigByToken" | "identity">;
|
|
150
244
|
};
|
|
151
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Extended auth API that includes enterprise SSO and SCIM namespaces.
|
|
247
|
+
*
|
|
248
|
+
* This type is the union of {@link AuthApiBase} plus `sso` (SSO connection
|
|
249
|
+
* management, OIDC/SAML, domain verification, policies, audit, webhooks)
|
|
250
|
+
* and `scim` (SCIM provisioning configuration). It is returned by
|
|
251
|
+
* {@link createAuth} only when `new SSO()` is included in the providers
|
|
252
|
+
* array; otherwise the narrower {@link AuthApiBase} is returned instead.
|
|
253
|
+
* Attempting to access `auth.sso` or `auth.scim` without an SSO provider
|
|
254
|
+
* produces a compile-time error because the return type narrows back to
|
|
255
|
+
* {@link AuthApiBase}.
|
|
256
|
+
*
|
|
257
|
+
* @typeParam TAuthorization - The authorization config, forwarded to
|
|
258
|
+
* {@link AuthApiBase} for typed role IDs and grant strings.
|
|
259
|
+
*/
|
|
152
260
|
type AuthApi<TAuthorization extends AuthAuthorizationConfig | undefined = undefined> = AuthApiBase<TAuthorization> & {
|
|
153
261
|
sso: PublicSsoApi;
|
|
154
262
|
scim: PublicScimApi;
|
|
155
263
|
};
|
|
156
264
|
/**
|
|
157
|
-
* The return type of
|
|
158
|
-
*
|
|
159
|
-
*
|
|
265
|
+
* The return type of {@link createAuth}.
|
|
266
|
+
*
|
|
267
|
+
* Resolves to {@link AuthApi} (with `sso` and `scim` namespaces) when
|
|
268
|
+
* `new SSO()` is present in the providers array, or to the narrower
|
|
269
|
+
* {@link AuthApiBase} otherwise. This conditional type ensures that
|
|
270
|
+
* enterprise-only APIs are only accessible when the SSO provider is
|
|
271
|
+
* configured, producing a compile-time error if you try to access
|
|
272
|
+
* `auth.sso` without it.
|
|
273
|
+
* This lets application code keep a single `createAuth()` call while still
|
|
274
|
+
* getting provider-aware typing on the resulting API object.
|
|
275
|
+
*
|
|
276
|
+
* @typeParam P - The tuple of provider configs passed to `createAuth`.
|
|
277
|
+
* @typeParam TAuthorization - Optional authorization config for typed roles/grants.
|
|
160
278
|
*/
|
|
161
279
|
type ConvexAuthResult<P extends AuthProviderConfig[], TAuthorization extends AuthAuthorizationConfig | undefined = undefined> = HasSSO<P> extends true ? AuthApi<TAuthorization> : AuthApiBase<TAuthorization>;
|
|
162
280
|
/**
|
|
@@ -170,28 +288,55 @@ type ConvexAuthResult<P extends AuthProviderConfig[], TAuthorization extends Aut
|
|
|
170
288
|
*
|
|
171
289
|
* // Frontend
|
|
172
290
|
* import type { auth } from "../convex/auth";
|
|
173
|
-
* import type { InferClientApi } from "@robelest/convex-auth/
|
|
291
|
+
* import type { InferClientApi } from "@robelest/convex-auth/server";
|
|
174
292
|
* const c = client<InferClientApi<typeof auth>>({ convex, api: api.auth });
|
|
175
293
|
* ```
|
|
176
|
-
*/
|
|
177
|
-
type InferClientApi<T> = T extends ConvexAuthResult<infer P> ? AuthApiRefs<HasPasskeyProvider<P>, HasTotpProvider<P>, HasDeviceProvider<P>> : AuthApiRefs;
|
|
178
|
-
/**
|
|
179
|
-
* Create an auth API object.
|
|
180
294
|
*
|
|
181
|
-
*
|
|
182
|
-
* are available on the returned object. Without it, those namespaces are
|
|
183
|
-
* absent and accessing them is a TypeScript compile error.
|
|
295
|
+
* @typeParam T - A ConvexAuthResult to extract the client API from.
|
|
184
296
|
*/
|
|
297
|
+
type InferClientApi<T> = T extends ConvexAuthResult<infer P> ? AuthApiRefs<HasPasskeyProvider<P>, HasTotpProvider<P>, HasDeviceProvider<P>> : AuthApiRefs;
|
|
185
298
|
declare function createAuth<P extends AuthProviderConfig[], TAuthorization extends AuthAuthorizationConfig | undefined = undefined>(component: ConvexAuthConfig["component"], config: Omit<AuthConfig, "providers" | "authorization"> & {
|
|
186
299
|
providers: P;
|
|
187
300
|
authorization?: TAuthorization;
|
|
188
301
|
}): ConvexAuthResult<P, TAuthorization>;
|
|
302
|
+
/** Canonical user document type exposed by Convex Auth. */
|
|
189
303
|
type UserDoc = Doc<"User">;
|
|
304
|
+
/**
|
|
305
|
+
* Configuration for {@link AuthCtx} context enrichment.
|
|
306
|
+
*
|
|
307
|
+
* @typeParam TResolve - Extra fields returned from `resolve()` and merged into
|
|
308
|
+
* the resulting `ctx.auth` object.
|
|
309
|
+
*/
|
|
190
310
|
type AuthCtxConfig<TResolve extends Record<string, unknown> = Record<string, never>> = {
|
|
191
|
-
optional?: boolean;
|
|
311
|
+
/** Allow unauthenticated callers and return `userId: null` / `user: null`. */optional?: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Attach additional derived fields to the auth context after the user is resolved.
|
|
314
|
+
*/
|
|
192
315
|
resolve?: (ctx: any, user: UserDoc) => Promise<TResolve> | TResolve;
|
|
193
316
|
};
|
|
194
|
-
/**
|
|
317
|
+
/**
|
|
318
|
+
* Create a context enrichment for `customQuery` / `customMutation` — optional auth.
|
|
319
|
+
*
|
|
320
|
+
* When `optional: true` is set, unauthenticated requests are allowed.
|
|
321
|
+
* The enriched `ctx.auth` will have `userId: null` and `user: null`
|
|
322
|
+
* for unauthenticated callers.
|
|
323
|
+
*
|
|
324
|
+
* @param auth - The auth API object returned by {@link createAuth}.
|
|
325
|
+
* @param config - Configuration with `optional: true` and an optional
|
|
326
|
+
* `resolve` callback for attaching extra fields to the auth context.
|
|
327
|
+
* @returns An object with `args` and `input` compatible with Convex
|
|
328
|
+
* custom function builders.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* const authCtx = AuthCtx(auth, {
|
|
333
|
+
* optional: true,
|
|
334
|
+
* resolve: async (_ctx, user) => ({ plan: user?.extend?.plan ?? null }),
|
|
335
|
+
* });
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @see {@link createAuth}
|
|
339
|
+
*/
|
|
195
340
|
declare function AuthCtx<TResolve extends Record<string, unknown> = Record<string, never>>(auth: AuthLike, config: AuthCtxConfig<TResolve> & {
|
|
196
341
|
optional: true;
|
|
197
342
|
}): {
|
|
@@ -207,7 +352,29 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
207
352
|
args: {};
|
|
208
353
|
}>;
|
|
209
354
|
};
|
|
210
|
-
/**
|
|
355
|
+
/**
|
|
356
|
+
* Create a context enrichment for `customQuery` / `customMutation` — required auth (default).
|
|
357
|
+
*
|
|
358
|
+
* When `optional` is omitted or `false`, the inferred type is the authenticated
|
|
359
|
+
* auth shape. At runtime this helper still resolves instead of throwing, so if
|
|
360
|
+
* no user is signed in the returned `ctx.auth.userId` and `ctx.auth.user` are
|
|
361
|
+
* `null`.
|
|
362
|
+
*
|
|
363
|
+
* @param auth - The auth API object returned by {@link createAuth}.
|
|
364
|
+
* @param config - Optional configuration with a `resolve` callback
|
|
365
|
+
* for attaching extra fields to the auth context.
|
|
366
|
+
* @returns An object with `args` and `input` compatible with Convex
|
|
367
|
+
* custom function builders.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* const authCtx = AuthCtx(auth, {
|
|
372
|
+
* resolve: async (_ctx, user) => ({ email: user.email }),
|
|
373
|
+
* });
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @see {@link createAuth}
|
|
377
|
+
*/
|
|
211
378
|
declare function AuthCtx<TResolve extends Record<string, unknown> = Record<string, never>>(auth: AuthLike, config?: AuthCtxConfig<TResolve>): {
|
|
212
379
|
args: {};
|
|
213
380
|
input: (ctx: any, _args: any, _extra?: any) => Promise<{
|
|
@@ -221,6 +388,29 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
221
388
|
args: {};
|
|
222
389
|
}>;
|
|
223
390
|
};
|
|
391
|
+
/**
|
|
392
|
+
* Extract the resolved `auth` context type from an {@link AuthCtx} instance.
|
|
393
|
+
*
|
|
394
|
+
* Use this to type function parameters or variables that receive the
|
|
395
|
+
* enriched auth context produced by `AuthCtx`. The inferred type includes
|
|
396
|
+
* `userId`, `user`, `getUserIdentity`, and any additional fields added
|
|
397
|
+
* by the `resolve` callback. This is the generic utility for reusing the
|
|
398
|
+
* enriched auth shape without manually duplicating conditional auth types.
|
|
399
|
+
*
|
|
400
|
+
* @typeParam T - An `AuthCtx` return value (must have an `input` method
|
|
401
|
+
* that returns `{ ctx: { auth: ... } }`).
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* const authCtx = AuthCtx(auth, {
|
|
406
|
+
* resolve: async (ctx, user) => ({ orgId: user.orgId }),
|
|
407
|
+
* });
|
|
408
|
+
* type Auth = InferAuth<typeof authCtx>;
|
|
409
|
+
* // Auth = { userId: Id<"User">; user: UserDoc; getUserIdentity: ...; orgId: string }
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @see {@link createAuth}
|
|
413
|
+
*/
|
|
224
414
|
type InferAuth<T extends {
|
|
225
415
|
input: (...args: any[]) => Promise<{
|
|
226
416
|
ctx: {
|
|
@@ -229,5 +419,5 @@ type InferAuth<T extends {
|
|
|
229
419
|
}>;
|
|
230
420
|
}> = Awaited<ReturnType<T["input"]>>["ctx"]["auth"];
|
|
231
421
|
//#endregion
|
|
232
|
-
export { AuthApi, AuthApiBase, AuthConfig, AuthCtx, AuthCtxConfig, ConvexAuthResult, InferAuth, InferClientApi, UserDoc, createAuth };
|
|
422
|
+
export { AuthApi, AuthApiBase, AuthConfig, AuthCtx, AuthCtxConfig, AuthResolvedContext, ConvexAuthResult, InferAuth, InferClientApi, UserDoc, createAuth };
|
|
233
423
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","names":[],"sources":["../../src/server/auth.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","names":[],"sources":["../../src/server/auth.ts"],"mappings":";;;;;;;;;;AAmC6D;;KAAjD,UAAA,GAAa,IAAA,CAAK,gBAAA;AAAA,KAEzB,0BAAA,wBACoB,uBAAA,gBACrB,IAAA,CACF,UAAA,QAAkB,MAAA;EAGlB,MAAA,GACE,GAAA,EAAK,UAAA,CACH,UAAA,QAAkB,MAAA,mCAEpB,IAAA;IACE,OAAA;IACA,MAAA;IACA,OAAA,GAAU,UAAA,CAAW,cAAA;IACrB,MAAA;IACA,MAAA,GAAS,MAAA;EAAA,MAER,OAAA;IAAU,EAAA;IAAU,QAAA;EAAA;EACzB,IAAA,GACE,GAAA,EAAK,UAAA,CACH,UAAA,QAAkB,MAAA,iCAEpB,IAAA;IACE,KAAA;MACE,OAAA;MACA,MAAA;MACA,MAAA,GAAS,UAAA,CAAW,cAAA;MACpB,MAAA;IAAA;IAEF,KAAA;IACA,MAAA;IACA,OAAA;IACA,KAAA;EAAA,MAEC,UAAA,CAAW,UAAA,QAAkB,MAAA;EAClC,MAAA,GACE,GAAA,EAAK,UAAA,CACH,UAAA,QAAkB,MAA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C/B,MAAA,EAAQ,SAAA;QACR,IAAA,EAAM,OAAA;MAAA,IACJ,QAAA;IAAA;IAEN,IAAA;EAAA;AAAA;;;;AAhawB;;;;;;;;;AAsB5B;;;;;;;;;;;iBAoagB,OAAA,kBACG,MAAA,oBAA0B,MAAA,gBAAA,CAE3C,IAAA,EAAM,QAAA,EACN,MAAA,GAAS,aAAA,CAAc,QAAA;EAEvB,IAAA;EACA,KAAA,GACE,GAAA,OACA,KAAA,OACA,MAAA,WACG,OAAA;IACH,GAAA;MACE,IAAA;QACE,eAAA,QAAuB,OAAA,CAAQ,YAAA;QAC/B,MAAA,EAAQ,SAAA;QACR,IAAA,EAAM,OAAA;MAAA,IACJ,QAAA;IAAA;IAEN,IAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;AAxYJ;;KAkeY,SAAA;EACE,KAAA,MAAW,IAAA,YAAgB,OAAA;IAAU,GAAA;MAAO,IAAA;IAAA;EAAA;AAAA,KACtD,OAAA,CAAQ,UAAA,CAAW,CAAA"}
|
package/dist/server/auth.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AuthError
|
|
2
|
-
import { Auth } from "./
|
|
1
|
+
import { AuthError } from "./authError.js";
|
|
2
|
+
import { Auth } from "./runtime.js";
|
|
3
|
+
import { Fx } from "@robelest/fx";
|
|
3
4
|
|
|
4
5
|
//#region src/server/auth.ts
|
|
5
6
|
/**
|
|
@@ -8,7 +9,61 @@ import { Auth } from "./factory.js";
|
|
|
8
9
|
* When `new SSO()` is included in providers, `auth.sso` and `auth.scim`
|
|
9
10
|
* are available on the returned object. Without it, those namespaces are
|
|
10
11
|
* absent and accessing them is a TypeScript compile error.
|
|
12
|
+
*
|
|
13
|
+
* @param component - The installed auth component reference from
|
|
14
|
+
* `components.auth` in your Convex app definition.
|
|
15
|
+
* @param config - Auth configuration including `providers` and optional
|
|
16
|
+
* `authorization`. All fields from {@link AuthConfig} are accepted
|
|
17
|
+
* except `component` (passed as the first argument).
|
|
18
|
+
* @returns A {@link ConvexAuthResult} object — either {@link AuthApi}
|
|
19
|
+
* (with `sso`/`scim`) or {@link AuthApiBase}, depending on whether
|
|
20
|
+
* an SSO provider is present.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* export const auth = createAuth(components.auth, {
|
|
25
|
+
* providers: [password(), google()],
|
|
26
|
+
* authorization: { roles },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @see {@link AuthCtx}
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Resolve auth context for the current user. Returns the enriched
|
|
34
|
+
* `ctx.auth` object or `null` when unauthenticated.
|
|
35
|
+
*
|
|
36
|
+
* Resolution flow:
|
|
37
|
+
* 1. `user.id(ctx)` → userId or null (exit early)
|
|
38
|
+
* 2. `user.get(ctx, userId)` → user doc (cached per-execution)
|
|
39
|
+
* 3. `user.getActiveGroup(ctx, { userId })` → groupId or null
|
|
40
|
+
* 4. If groupId → `member.resolve(ctx, { userId, groupId })` → role + grants
|
|
11
41
|
*/
|
|
42
|
+
async function resolveAuthContext(auth, ctx) {
|
|
43
|
+
const userId = await auth.user.id(ctx);
|
|
44
|
+
if (!userId) return null;
|
|
45
|
+
const user = await auth.user.get(ctx, userId);
|
|
46
|
+
const groupId = await auth.user.getActiveGroup(ctx, { userId });
|
|
47
|
+
let role = null;
|
|
48
|
+
let grants = [];
|
|
49
|
+
if (groupId) {
|
|
50
|
+
const resolved = await auth.member.resolve(ctx, {
|
|
51
|
+
userId,
|
|
52
|
+
groupId
|
|
53
|
+
});
|
|
54
|
+
if (resolved.membership) {
|
|
55
|
+
role = resolved.roleIds[0] ?? null;
|
|
56
|
+
grants = resolved.grants;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
userId,
|
|
61
|
+
user,
|
|
62
|
+
groupId,
|
|
63
|
+
role,
|
|
64
|
+
grants
|
|
65
|
+
};
|
|
66
|
+
}
|
|
12
67
|
function createAuth(component, config) {
|
|
13
68
|
const authResult = Auth({
|
|
14
69
|
...config,
|
|
@@ -105,7 +160,6 @@ function createAuth(component, config) {
|
|
|
105
160
|
account: authResult.auth.account,
|
|
106
161
|
group: authResult.auth.group,
|
|
107
162
|
member: authResult.auth.member,
|
|
108
|
-
access: authResult.auth.access,
|
|
109
163
|
invite: authResult.auth.invite,
|
|
110
164
|
key: authResult.auth.key,
|
|
111
165
|
sso: publicSso,
|
|
@@ -114,7 +168,17 @@ function createAuth(component, config) {
|
|
|
114
168
|
get: scimApi.get,
|
|
115
169
|
validate: scimApi.validate
|
|
116
170
|
} },
|
|
117
|
-
http: authResult.auth.http
|
|
171
|
+
http: authResult.auth.http,
|
|
172
|
+
resolve: (ctx) => resolveAuthContext(authResult.auth, ctx),
|
|
173
|
+
ctx: () => ({
|
|
174
|
+
args: {},
|
|
175
|
+
input: async (ctx) => {
|
|
176
|
+
return {
|
|
177
|
+
ctx: { auth: await resolveAuthContext(authResult.auth, ctx) },
|
|
178
|
+
args: {}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
})
|
|
118
182
|
};
|
|
119
183
|
}
|
|
120
184
|
function AuthCtx(auth, config) {
|