@robelest/convex-auth 0.0.4-preview.21 → 0.0.4-preview.23
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/dist/authorization/index.d.ts +1 -1
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/index.js.map +1 -1
- package/dist/client/index.d.ts +1 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +36 -39
- package/dist/client/index.js.map +1 -1
- package/dist/component/client/index.d.ts +1 -2
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/convex.config.d.ts.map +1 -1
- package/dist/component/model.d.ts +5 -5
- package/dist/component/model.d.ts.map +1 -1
- package/dist/component/public/enterprise/audit.d.ts.map +1 -1
- package/dist/component/public/enterprise/audit.js.map +1 -1
- package/dist/component/public/enterprise/core.d.ts.map +1 -1
- package/dist/component/public/enterprise/core.js.map +1 -1
- package/dist/component/public/enterprise/domains.d.ts.map +1 -1
- package/dist/component/public/enterprise/domains.js.map +1 -1
- package/dist/component/public/enterprise/scim.d.ts.map +1 -1
- package/dist/component/public/enterprise/scim.js.map +1 -1
- package/dist/component/public/enterprise/secrets.d.ts.map +1 -1
- package/dist/component/public/enterprise/secrets.js.map +1 -1
- package/dist/component/public/enterprise/webhooks.d.ts.map +1 -1
- package/dist/component/public/enterprise/webhooks.js.map +1 -1
- package/dist/component/public/factors/devices.d.ts.map +1 -1
- package/dist/component/public/factors/devices.js.map +1 -1
- package/dist/component/public/factors/passkeys.d.ts.map +1 -1
- package/dist/component/public/factors/passkeys.js.map +1 -1
- package/dist/component/public/factors/totp.d.ts.map +1 -1
- package/dist/component/public/factors/totp.js.map +1 -1
- package/dist/component/public/groups/core.js.map +1 -1
- package/dist/component/public/groups/invites.d.ts.map +1 -1
- package/dist/component/public/groups/invites.js.map +1 -1
- package/dist/component/public/groups/members.d.ts.map +1 -1
- package/dist/component/public/groups/members.js.map +1 -1
- package/dist/component/public/identity/accounts.d.ts.map +1 -1
- package/dist/component/public/identity/accounts.js.map +1 -1
- package/dist/component/public/identity/codes.d.ts.map +1 -1
- package/dist/component/public/identity/codes.js.map +1 -1
- package/dist/component/public/identity/sessions.d.ts.map +1 -1
- package/dist/component/public/identity/sessions.js.map +1 -1
- package/dist/component/public/identity/tokens.d.ts.map +1 -1
- package/dist/component/public/identity/tokens.js.map +1 -1
- package/dist/component/public/identity/users.d.ts.map +1 -1
- package/dist/component/public/identity/users.js.map +1 -1
- package/dist/component/public/identity/verifiers.d.ts.map +1 -1
- package/dist/component/public/identity/verifiers.js.map +1 -1
- package/dist/component/public/security/keys.d.ts.map +1 -1
- package/dist/component/public/security/keys.js.map +1 -1
- package/dist/component/public/security/limits.d.ts.map +1 -1
- package/dist/component/public/security/limits.js.map +1 -1
- package/dist/component/schema.d.ts +39 -39
- package/dist/component/server/auth.d.ts +95 -52
- package/dist/component/server/auth.d.ts.map +1 -1
- package/dist/component/server/auth.js +63 -43
- package/dist/component/server/auth.js.map +1 -1
- package/dist/component/server/core.js +116 -235
- package/dist/component/server/core.js.map +1 -1
- package/dist/component/server/crypto.js +25 -7
- package/dist/component/server/crypto.js.map +1 -1
- package/dist/component/server/device.js +58 -15
- package/dist/component/server/device.js.map +1 -1
- package/dist/component/server/enterprise/domain.js +148 -59
- package/dist/component/server/enterprise/domain.js.map +1 -1
- package/dist/component/server/enterprise/http.js +36 -15
- package/dist/component/server/enterprise/http.js.map +1 -1
- package/dist/component/server/enterprise/oidc.js +1 -1
- package/dist/component/server/http.js +26 -21
- package/dist/component/server/http.js.map +1 -1
- package/dist/component/server/identity.js +5 -2
- package/dist/component/server/identity.js.map +1 -1
- package/dist/component/server/limits.js +21 -30
- package/dist/component/server/limits.js.map +1 -1
- package/dist/component/server/mutations/account.js +12 -10
- package/dist/component/server/mutations/account.js.map +1 -1
- package/dist/component/server/mutations/code.js +5 -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 +10 -4
- package/dist/component/server/mutations/oauth.js.map +1 -1
- package/dist/component/server/mutations/refresh.js +2 -2
- package/dist/component/server/mutations/refresh.js.map +1 -1
- package/dist/component/server/mutations/register.js +46 -42
- package/dist/component/server/mutations/register.js.map +1 -1
- package/dist/component/server/mutations/retrieve.js +21 -25
- package/dist/component/server/mutations/retrieve.js.map +1 -1
- package/dist/component/server/mutations/signature.js +10 -4
- package/dist/component/server/mutations/signature.js.map +1 -1
- package/dist/component/server/mutations/signout.js.map +1 -1
- package/dist/component/server/mutations/store.js +9 -24
- package/dist/component/server/mutations/store.js.map +1 -1
- package/dist/component/server/mutations/verifier.js.map +1 -1
- package/dist/component/server/mutations/verify.js +1 -1
- package/dist/component/server/mutations/verify.js.map +1 -1
- package/dist/component/server/oauth.js +53 -16
- package/dist/component/server/oauth.js.map +1 -1
- package/dist/component/server/passkey.js +115 -31
- package/dist/component/server/passkey.js.map +1 -1
- package/dist/component/server/redirects.js +9 -3
- package/dist/component/server/redirects.js.map +1 -1
- package/dist/component/server/refresh.js +10 -7
- package/dist/component/server/refresh.js.map +1 -1
- package/dist/component/server/runtime.d.ts +3 -3
- package/dist/component/server/runtime.d.ts.map +1 -1
- package/dist/component/server/runtime.js +62 -20
- package/dist/component/server/runtime.js.map +1 -1
- package/dist/component/server/signin.js +34 -10
- package/dist/component/server/signin.js.map +1 -1
- package/dist/component/server/totp.js +79 -19
- package/dist/component/server/totp.js.map +1 -1
- package/dist/component/server/types.d.ts +12 -20
- 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 +6 -3
- package/dist/component/server/users.js.map +1 -1
- package/dist/component/server/utils.js +10 -4
- package/dist/component/server/utils.js.map +1 -1
- package/dist/core/types.d.ts +14 -22
- package/dist/core/types.d.ts.map +1 -1
- package/dist/factors/device.js +8 -9
- package/dist/factors/device.js.map +1 -1
- package/dist/factors/passkey.js +18 -21
- package/dist/factors/passkey.js.map +1 -1
- package/dist/providers/password.js +66 -81
- package/dist/providers/password.js.map +1 -1
- package/dist/runtime/invite.js +2 -8
- package/dist/runtime/invite.js.map +1 -1
- package/dist/server/auth.d.ts +95 -52
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +63 -43
- package/dist/server/auth.js.map +1 -1
- package/dist/server/core.d.ts +71 -159
- package/dist/server/core.d.ts.map +1 -1
- package/dist/server/core.js +116 -235
- package/dist/server/core.js.map +1 -1
- package/dist/server/crypto.d.ts.map +1 -1
- package/dist/server/crypto.js +25 -7
- package/dist/server/crypto.js.map +1 -1
- package/dist/server/device.js +58 -15
- package/dist/server/device.js.map +1 -1
- package/dist/server/enterprise/domain.d.ts +0 -8
- package/dist/server/enterprise/domain.d.ts.map +1 -1
- package/dist/server/enterprise/domain.js +148 -59
- package/dist/server/enterprise/domain.js.map +1 -1
- package/dist/server/enterprise/http.d.ts.map +1 -1
- package/dist/server/enterprise/http.js +35 -14
- package/dist/server/enterprise/http.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 +25 -20
- package/dist/server/http.js.map +1 -1
- package/dist/server/identity.js +5 -2
- package/dist/server/identity.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/limits.js +21 -30
- package/dist/server/limits.js.map +1 -1
- package/dist/server/mounts.d.ts +26 -64
- package/dist/server/mounts.d.ts.map +1 -1
- package/dist/server/mounts.js +45 -106
- package/dist/server/mounts.js.map +1 -1
- package/dist/server/mutations/account.d.ts +8 -9
- package/dist/server/mutations/account.d.ts.map +1 -1
- package/dist/server/mutations/account.js +11 -9
- package/dist/server/mutations/account.js.map +1 -1
- package/dist/server/mutations/code.d.ts +13 -13
- package/dist/server/mutations/code.d.ts.map +1 -1
- package/dist/server/mutations/code.js +5 -2
- package/dist/server/mutations/code.js.map +1 -1
- package/dist/server/mutations/invalidate.d.ts +4 -4
- package/dist/server/mutations/invalidate.d.ts.map +1 -1
- package/dist/server/mutations/invalidate.js.map +1 -1
- package/dist/server/mutations/oauth.d.ts +12 -10
- package/dist/server/mutations/oauth.d.ts.map +1 -1
- package/dist/server/mutations/oauth.js +9 -3
- package/dist/server/mutations/oauth.js.map +1 -1
- package/dist/server/mutations/refresh.d.ts +3 -3
- package/dist/server/mutations/refresh.d.ts.map +1 -1
- package/dist/server/mutations/refresh.js +1 -1
- package/dist/server/mutations/refresh.js.map +1 -1
- package/dist/server/mutations/register.d.ts +11 -11
- package/dist/server/mutations/register.d.ts.map +1 -1
- package/dist/server/mutations/register.js +45 -41
- package/dist/server/mutations/register.js.map +1 -1
- package/dist/server/mutations/retrieve.d.ts +6 -6
- package/dist/server/mutations/retrieve.d.ts.map +1 -1
- package/dist/server/mutations/retrieve.js +20 -24
- package/dist/server/mutations/retrieve.js.map +1 -1
- package/dist/server/mutations/signature.d.ts +6 -7
- package/dist/server/mutations/signature.d.ts.map +1 -1
- package/dist/server/mutations/signature.js +9 -3
- package/dist/server/mutations/signature.js.map +1 -1
- package/dist/server/mutations/signin.d.ts +5 -5
- package/dist/server/mutations/signin.d.ts.map +1 -1
- package/dist/server/mutations/signout.js.map +1 -1
- package/dist/server/mutations/store.d.ts +97 -97
- package/dist/server/mutations/store.d.ts.map +1 -1
- package/dist/server/mutations/store.js +8 -23
- package/dist/server/mutations/store.js.map +1 -1
- package/dist/server/mutations/verifier.js.map +1 -1
- package/dist/server/mutations/verify.d.ts +10 -10
- package/dist/server/mutations/verify.d.ts.map +1 -1
- package/dist/server/mutations/verify.js.map +1 -1
- package/dist/server/oauth.js +53 -16
- 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 +114 -30
- package/dist/server/passkey.js.map +1 -1
- package/dist/server/redirects.js +9 -3
- package/dist/server/redirects.js.map +1 -1
- package/dist/server/refresh.js +10 -7
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/runtime.d.ts +14 -14
- package/dist/server/runtime.d.ts.map +1 -1
- package/dist/server/runtime.js +61 -19
- package/dist/server/runtime.js.map +1 -1
- package/dist/server/signin.js +34 -10
- package/dist/server/signin.js.map +1 -1
- package/dist/server/ssr.d.ts.map +1 -1
- package/dist/server/ssr.js +175 -184
- package/dist/server/ssr.js.map +1 -1
- package/dist/server/totp.js +78 -18
- package/dist/server/totp.js.map +1 -1
- package/dist/server/types.d.ts +13 -21
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js.map +1 -1
- package/dist/server/users.js +6 -3
- package/dist/server/users.js.map +1 -1
- package/dist/server/utils.js +10 -4
- package/dist/server/utils.js.map +1 -1
- package/package.json +2 -6
- package/src/authorization/index.ts +1 -1
- package/src/cli/index.ts +1 -1
- package/src/client/core/types.ts +14 -14
- package/src/client/factors/device.ts +10 -12
- package/src/client/factors/passkey.ts +23 -26
- package/src/client/index.ts +54 -64
- package/src/client/runtime/invite.ts +5 -7
- package/src/component/index.ts +1 -0
- package/src/component/public/enterprise/audit.ts +6 -1
- package/src/component/public/enterprise/core.ts +1 -0
- package/src/component/public/enterprise/domains.ts +5 -1
- package/src/component/public/enterprise/scim.ts +1 -0
- package/src/component/public/enterprise/secrets.ts +1 -0
- package/src/component/public/enterprise/webhooks.ts +1 -0
- package/src/component/public/factors/devices.ts +1 -0
- package/src/component/public/factors/passkeys.ts +1 -0
- package/src/component/public/factors/totp.ts +1 -0
- package/src/component/public/groups/core.ts +1 -1
- package/src/component/public/groups/invites.ts +7 -1
- package/src/component/public/groups/members.ts +1 -0
- package/src/component/public/identity/accounts.ts +1 -0
- package/src/component/public/identity/codes.ts +1 -0
- package/src/component/public/identity/sessions.ts +1 -0
- package/src/component/public/identity/tokens.ts +1 -0
- package/src/component/public/identity/users.ts +1 -0
- package/src/component/public/identity/verifiers.ts +1 -0
- package/src/component/public/security/keys.ts +1 -0
- package/src/component/public/security/limits.ts +1 -0
- package/src/providers/password.ts +89 -110
- package/src/server/auth.ts +177 -111
- package/src/server/core.ts +197 -233
- package/src/server/crypto.ts +31 -29
- package/src/server/device.ts +65 -32
- package/src/server/enterprise/domain.ts +158 -170
- package/src/server/enterprise/http.ts +46 -39
- package/src/server/http.ts +36 -30
- package/src/server/identity.ts +5 -5
- package/src/server/index.ts +2 -0
- package/src/server/limits.ts +53 -80
- package/src/server/mounts.ts +47 -74
- package/src/server/mutations/account.ts +22 -36
- package/src/server/mutations/code.ts +6 -6
- package/src/server/mutations/invalidate.ts +1 -1
- package/src/server/mutations/oauth.ts +14 -8
- package/src/server/mutations/refresh.ts +5 -4
- package/src/server/mutations/register.ts +87 -132
- package/src/server/mutations/retrieve.ts +44 -44
- package/src/server/mutations/signature.ts +13 -6
- package/src/server/mutations/signout.ts +1 -1
- package/src/server/mutations/store.ts +16 -31
- package/src/server/mutations/verifier.ts +1 -1
- package/src/server/mutations/verify.ts +3 -5
- package/src/server/oauth.ts +60 -69
- package/src/server/passkey.ts +567 -517
- package/src/server/redirects.ts +10 -6
- package/src/server/refresh.ts +14 -18
- package/src/server/runtime.ts +70 -55
- package/src/server/signin.ts +44 -37
- package/src/server/ssr.ts +390 -407
- package/src/server/totp.ts +85 -35
- package/src/server/types.ts +19 -22
- package/src/server/users.ts +7 -6
- package/src/server/utils.ts +10 -12
- package/dist/component/server/authError.js +0 -34
- package/dist/component/server/authError.js.map +0 -1
- package/dist/component/server/errors.d.ts +0 -1
- package/dist/component/server/errors.js +0 -137
- package/dist/component/server/errors.js.map +0 -1
- package/dist/server/authError.d.ts +0 -46
- package/dist/server/authError.d.ts.map +0 -1
- package/dist/server/authError.js +0 -34
- package/dist/server/authError.js.map +0 -1
- package/dist/server/errors.d.ts +0 -177
- package/dist/server/errors.d.ts.map +0 -1
- package/dist/server/errors.js +0 -212
- package/dist/server/errors.js.map +0 -1
- package/src/server/authError.ts +0 -44
- package/src/server/errors.ts +0 -290
package/dist/server/auth.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ import { GenericId } from "convex/values";
|
|
|
11
11
|
* minus `component` (which is passed as the first constructor argument).
|
|
12
12
|
*/
|
|
13
13
|
type AuthConfig = Omit<ConvexAuthConfig, "component">;
|
|
14
|
-
|
|
14
|
+
/** Canonical user document type exposed by Convex Auth. */
|
|
15
|
+
type UserDoc = Doc<"User">;
|
|
16
|
+
type MemberApiWithAuthorization<TAuthorization extends AuthAuthorizationConfig | undefined> = Omit<ReturnType<typeof Auth$1>["auth"]["member"], "create" | "list" | "update" | "inspect" | "require"> & {
|
|
15
17
|
create: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["create"]>[0], data: {
|
|
16
18
|
groupId: string;
|
|
17
19
|
userId: string;
|
|
@@ -19,7 +21,6 @@ type MemberApiWithAuthorization<TAuthorization extends AuthAuthorizationConfig |
|
|
|
19
21
|
status?: string;
|
|
20
22
|
extend?: Record<string, unknown>;
|
|
21
23
|
}) => Promise<{
|
|
22
|
-
ok: true;
|
|
23
24
|
memberId: string;
|
|
24
25
|
}>;
|
|
25
26
|
list: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["list"]>[0], opts?: {
|
|
@@ -37,17 +38,22 @@ type MemberApiWithAuthorization<TAuthorization extends AuthAuthorizationConfig |
|
|
|
37
38
|
update: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["update"]>[0], memberId: string, data: Record<string, unknown> & {
|
|
38
39
|
roleIds?: AuthRoleId<TAuthorization>[];
|
|
39
40
|
}) => Promise<{
|
|
40
|
-
ok: true;
|
|
41
41
|
memberId: string;
|
|
42
42
|
}>;
|
|
43
|
-
|
|
43
|
+
inspect: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["inspect"]>[0], opts: {
|
|
44
|
+
userId: string;
|
|
45
|
+
groupId: string;
|
|
46
|
+
ancestry?: boolean;
|
|
47
|
+
maxDepth?: number;
|
|
48
|
+
}) => ReturnType<ReturnType<typeof Auth$1>["auth"]["member"]["inspect"]>;
|
|
49
|
+
require: (ctx: Parameters<ReturnType<typeof Auth$1>["auth"]["member"]["require"]>[0], opts: {
|
|
44
50
|
userId: string;
|
|
45
51
|
groupId: string;
|
|
46
52
|
ancestry?: boolean;
|
|
47
53
|
roleIds?: AuthRoleId<TAuthorization>[];
|
|
48
54
|
grants?: AuthGrant<TAuthorization>[];
|
|
49
55
|
maxDepth?: number;
|
|
50
|
-
}) => ReturnType<ReturnType<typeof Auth$1>["auth"]["member"]["
|
|
56
|
+
}) => ReturnType<ReturnType<typeof Auth$1>["auth"]["member"]["require"]>;
|
|
51
57
|
};
|
|
52
58
|
/**
|
|
53
59
|
* The base auth API surface returned by {@link createAuth}.
|
|
@@ -78,30 +84,29 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
78
84
|
key: ReturnType<typeof Auth$1>["auth"]["key"];
|
|
79
85
|
http: ReturnType<typeof Auth$1>["auth"]["http"];
|
|
80
86
|
/**
|
|
81
|
-
* Resolve the current
|
|
87
|
+
* Resolve the current request's auth context. Framework-agnostic — use
|
|
82
88
|
* this in fluent-convex middleware, custom wrappers, or anywhere you
|
|
83
|
-
* need the
|
|
89
|
+
* need the current `{ userId, user, groupId, role, grants }` object.
|
|
84
90
|
*
|
|
85
|
-
*
|
|
91
|
+
* Throws a structured `ConvexError` when unauthenticated.
|
|
86
92
|
*
|
|
87
93
|
* @param ctx - Convex query, mutation, or action context.
|
|
88
|
-
* @returns The
|
|
94
|
+
* @returns The current auth context.
|
|
89
95
|
*
|
|
90
96
|
* @example fluent-convex middleware
|
|
91
97
|
* ```ts
|
|
92
98
|
* const withAuth = convex.createMiddleware(async (ctx, next) => {
|
|
93
|
-
* return next({ ...ctx, auth: await auth.
|
|
99
|
+
* return next({ ...ctx, auth: await auth.context(ctx) });
|
|
94
100
|
* });
|
|
95
101
|
* ```
|
|
96
102
|
*
|
|
97
103
|
* @example Direct usage in a handler
|
|
98
104
|
* ```ts
|
|
99
|
-
* const
|
|
100
|
-
*
|
|
101
|
-
* const { userId, grants } = resolved;
|
|
105
|
+
* const authContext = await auth.context(ctx);
|
|
106
|
+
* const { userId, grants } = authContext;
|
|
102
107
|
* ```
|
|
103
108
|
*/
|
|
104
|
-
|
|
109
|
+
context: (ctx: any) => Promise<AuthContext>;
|
|
105
110
|
/**
|
|
106
111
|
* Context enrichment for convex-helpers `customQuery` / `customMutation` /
|
|
107
112
|
* `customAction`.
|
|
@@ -110,9 +115,9 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
110
115
|
* and grants, then attaches them to `ctx.auth`. Returns a `Customization`
|
|
111
116
|
* object compatible with convex-helpers' custom function builders.
|
|
112
117
|
*
|
|
113
|
-
* `ctx.auth` is
|
|
114
|
-
*
|
|
115
|
-
*
|
|
118
|
+
* `ctx.auth` is the current request auth context.
|
|
119
|
+
* By default this throws when unauthenticated so handlers can assume
|
|
120
|
+
* `ctx.auth.userId` and `ctx.auth.user` exist.
|
|
116
121
|
*
|
|
117
122
|
* @returns A convex-helpers `Customization` object.
|
|
118
123
|
*
|
|
@@ -134,7 +139,6 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
134
139
|
* export const list = authQuery({
|
|
135
140
|
* args: { workspaceId: v.string() },
|
|
136
141
|
* handler: async (ctx, args) => {
|
|
137
|
-
* if (!ctx.auth) return [];
|
|
138
142
|
* const { userId, groupId, grants } = ctx.auth;
|
|
139
143
|
* // business logic
|
|
140
144
|
* },
|
|
@@ -145,26 +149,53 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
145
149
|
args: Record<string, never>;
|
|
146
150
|
input: (ctx: any) => Promise<{
|
|
147
151
|
ctx: {
|
|
148
|
-
auth:
|
|
152
|
+
auth: AuthContext;
|
|
149
153
|
};
|
|
150
154
|
args: Record<string, never>;
|
|
151
155
|
}>;
|
|
152
156
|
};
|
|
153
157
|
};
|
|
154
158
|
/**
|
|
155
|
-
*
|
|
159
|
+
* Current request auth context injected into `ctx.auth` by `auth.ctx()` and
|
|
160
|
+
* {@link AuthCtx}. This is the authenticated auth shape returned by
|
|
161
|
+
* {@link createAuth().context}. Optional context builders may still surface
|
|
162
|
+
* nullable fields when `optional: true` is used.
|
|
156
163
|
*
|
|
157
|
-
* - `null` when unauthenticated.
|
|
158
164
|
* - `groupId` is `null` when the user has no active group set.
|
|
159
|
-
* - `role`
|
|
165
|
+
* - `role` is `null` when no active group or no membership is resolved.
|
|
166
|
+
* - `grants` is `[]` when no active group or no membership is resolved.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* import type { AuthContext } from "@robelest/convex-auth/server";
|
|
171
|
+
*
|
|
172
|
+
* const mockAuth: AuthContext = {
|
|
173
|
+
* userId: "user123" as Id<"User">,
|
|
174
|
+
* user: { _id: "user123", email: "test@example.com" },
|
|
175
|
+
* groupId: "group456",
|
|
176
|
+
* role: "admin",
|
|
177
|
+
* grants: ["read", "write"],
|
|
178
|
+
* };
|
|
179
|
+
* ```
|
|
160
180
|
*/
|
|
161
|
-
type
|
|
162
|
-
/** The authenticated user's document ID. */userId:
|
|
163
|
-
user:
|
|
181
|
+
type AuthContext = {
|
|
182
|
+
/** The authenticated user's document ID. */userId: GenericId<"User">; /** The authenticated user's full document. */
|
|
183
|
+
user: UserDoc; /** The user's active group ID, or `null` if none set. */
|
|
164
184
|
groupId: string | null; /** The user's primary role in the active group, or `null`. */
|
|
165
185
|
role: string | null; /** Resolved grant strings from the user's role definitions. */
|
|
166
186
|
grants: string[];
|
|
167
187
|
};
|
|
188
|
+
type AuthCtxBase = {
|
|
189
|
+
getUserIdentity: () => Promise<UserIdentity | null>;
|
|
190
|
+
};
|
|
191
|
+
type RequiredAuthCtxState = AuthCtxBase & AuthContext;
|
|
192
|
+
type OptionalAuthCtxState = AuthCtxBase & {
|
|
193
|
+
userId: GenericId<"User"> | null;
|
|
194
|
+
user: UserDoc | null;
|
|
195
|
+
groupId: string | null;
|
|
196
|
+
role: string | null;
|
|
197
|
+
grants: string[];
|
|
198
|
+
};
|
|
168
199
|
type InternalSsoApi = ReturnType<typeof Auth$1>["auth"]["sso"];
|
|
169
200
|
type PublicSsoAdminApi = {
|
|
170
201
|
connection: InternalSsoApi["connection"] & {
|
|
@@ -175,7 +206,6 @@ type PublicSsoAdminApi = {
|
|
|
175
206
|
domain: string;
|
|
176
207
|
isPrimary?: boolean;
|
|
177
208
|
}>) => Promise<{
|
|
178
|
-
ok: true;
|
|
179
209
|
enterpriseId: string;
|
|
180
210
|
domains: Array<{
|
|
181
211
|
domainId: string;
|
|
@@ -190,7 +220,6 @@ type PublicSsoAdminApi = {
|
|
|
190
220
|
enterpriseId: string;
|
|
191
221
|
domain: string;
|
|
192
222
|
}) => Promise<{
|
|
193
|
-
ok: true;
|
|
194
223
|
enterpriseId: string;
|
|
195
224
|
domain: string;
|
|
196
225
|
requestedAt: number;
|
|
@@ -205,7 +234,6 @@ type PublicSsoAdminApi = {
|
|
|
205
234
|
enterpriseId: string;
|
|
206
235
|
domain: string;
|
|
207
236
|
}) => Promise<{
|
|
208
|
-
ok: boolean;
|
|
209
237
|
enterpriseId: string;
|
|
210
238
|
domain: string;
|
|
211
239
|
verifiedAt?: number;
|
|
@@ -299,8 +327,6 @@ declare function createAuth<P extends AuthProviderConfig[], TAuthorization exten
|
|
|
299
327
|
providers: P;
|
|
300
328
|
authorization?: TAuthorization;
|
|
301
329
|
}): ConvexAuthResult<P, TAuthorization>;
|
|
302
|
-
/** Canonical user document type exposed by Convex Auth. */
|
|
303
|
-
type UserDoc = Doc<"User">;
|
|
304
330
|
/**
|
|
305
331
|
* Configuration for {@link AuthCtx} context enrichment.
|
|
306
332
|
*
|
|
@@ -310,16 +336,42 @@ type UserDoc = Doc<"User">;
|
|
|
310
336
|
type AuthCtxConfig<TResolve extends Record<string, unknown> = Record<string, never>> = {
|
|
311
337
|
/** Allow unauthenticated callers and return `userId: null` / `user: null`. */optional?: boolean;
|
|
312
338
|
/**
|
|
313
|
-
* Attach additional derived fields to the auth context after the
|
|
339
|
+
* Attach additional derived fields to the auth context after the base auth
|
|
340
|
+
* context is resolved.
|
|
341
|
+
*/
|
|
342
|
+
resolve?: (ctx: any, user: UserDoc, auth: AuthContext) => Promise<TResolve> | TResolve;
|
|
343
|
+
/**
|
|
344
|
+
* Override or wrap the base auth resolution used by {@link AuthCtx}.
|
|
345
|
+
*
|
|
346
|
+
* Return `undefined` to fall back to the built-in resolver,
|
|
347
|
+
* `null` for an explicit unauthenticated state, or an
|
|
348
|
+
* {@link AuthContext} object to provide a pre-resolved auth state.
|
|
349
|
+
* This is useful for tests, proxy auth, impersonation flows, or any
|
|
350
|
+
* environment that needs to inject auth without depending on the standard
|
|
351
|
+
* Convex auth tables.
|
|
352
|
+
*
|
|
353
|
+
* @param ctx - The Convex function context.
|
|
354
|
+
* @param fallback - The built-in auth resolver used by {@link AuthCtx}.
|
|
355
|
+
* @returns Resolved auth state, `null`, or `undefined` to use the fallback.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* const authCtx = AuthCtx(auth, {
|
|
360
|
+
* authResolve: async (ctx, fallback) => {
|
|
361
|
+
* const injected = getInjectedAuth(ctx);
|
|
362
|
+
* return injected ?? (await fallback());
|
|
363
|
+
* },
|
|
364
|
+
* });
|
|
365
|
+
* ```
|
|
314
366
|
*/
|
|
315
|
-
|
|
367
|
+
authResolve?: (ctx: any, fallback: () => Promise<AuthContext | null>) => Promise<AuthContext | null | undefined> | AuthContext | null | undefined;
|
|
316
368
|
};
|
|
317
369
|
/**
|
|
318
370
|
* Create a context enrichment for `customQuery` / `customMutation` — optional auth.
|
|
319
371
|
*
|
|
320
372
|
* When `optional: true` is set, unauthenticated requests are allowed.
|
|
321
|
-
* The enriched `ctx.auth` will have `userId: null
|
|
322
|
-
* for unauthenticated callers.
|
|
373
|
+
* The enriched `ctx.auth` will have `userId: null`, `user: null`,
|
|
374
|
+
* `groupId: null`, `role: null`, and `grants: []` for unauthenticated callers.
|
|
323
375
|
*
|
|
324
376
|
* @param auth - The auth API object returned by {@link createAuth}.
|
|
325
377
|
* @param config - Configuration with `optional: true` and an optional
|
|
@@ -343,11 +395,7 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
343
395
|
args: {};
|
|
344
396
|
input: (ctx: any, _args: any, _extra?: any) => Promise<{
|
|
345
397
|
ctx: {
|
|
346
|
-
auth:
|
|
347
|
-
getUserIdentity: () => Promise<UserIdentity | null>;
|
|
348
|
-
userId: GenericId<"User"> | null;
|
|
349
|
-
user: UserDoc | null;
|
|
350
|
-
} & TResolve;
|
|
398
|
+
auth: OptionalAuthCtxState & TResolve;
|
|
351
399
|
};
|
|
352
400
|
args: {};
|
|
353
401
|
}>;
|
|
@@ -355,10 +403,8 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
355
403
|
/**
|
|
356
404
|
* Create a context enrichment for `customQuery` / `customMutation` — required auth (default).
|
|
357
405
|
*
|
|
358
|
-
* When `optional` is omitted or `false`,
|
|
359
|
-
*
|
|
360
|
-
* no user is signed in the returned `ctx.auth.userId` and `ctx.auth.user` are
|
|
361
|
-
* `null`.
|
|
406
|
+
* When `optional` is omitted or `false`, unauthenticated requests throw a
|
|
407
|
+
* structured `ConvexError` before your handler runs.
|
|
362
408
|
*
|
|
363
409
|
* @param auth - The auth API object returned by {@link createAuth}.
|
|
364
410
|
* @param config - Optional configuration with a `resolve` callback
|
|
@@ -379,11 +425,7 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
379
425
|
args: {};
|
|
380
426
|
input: (ctx: any, _args: any, _extra?: any) => Promise<{
|
|
381
427
|
ctx: {
|
|
382
|
-
auth:
|
|
383
|
-
getUserIdentity: () => Promise<UserIdentity | null>;
|
|
384
|
-
userId: GenericId<"User">;
|
|
385
|
-
user: UserDoc;
|
|
386
|
-
} & TResolve;
|
|
428
|
+
auth: RequiredAuthCtxState & TResolve;
|
|
387
429
|
};
|
|
388
430
|
args: {};
|
|
389
431
|
}>;
|
|
@@ -393,9 +435,10 @@ declare function AuthCtx<TResolve extends Record<string, unknown> = Record<strin
|
|
|
393
435
|
*
|
|
394
436
|
* Use this to type function parameters or variables that receive the
|
|
395
437
|
* enriched auth context produced by `AuthCtx`. The inferred type includes
|
|
396
|
-
* `userId`, `user`, `getUserIdentity`, and any
|
|
397
|
-
* by the `resolve` callback. This is the generic
|
|
398
|
-
* enriched auth shape without manually duplicating
|
|
438
|
+
* `userId`, `user`, `groupId`, `role`, `grants`, `getUserIdentity`, and any
|
|
439
|
+
* additional fields added by the `resolve` callback. This is the generic
|
|
440
|
+
* utility for reusing the enriched auth shape without manually duplicating
|
|
441
|
+
* conditional auth types.
|
|
399
442
|
*
|
|
400
443
|
* @typeParam T - An `AuthCtx` return value (must have an `input` method
|
|
401
444
|
* that returns `{ ctx: { auth: ... } }`).
|
|
@@ -419,5 +462,5 @@ type InferAuth<T extends {
|
|
|
419
462
|
}>;
|
|
420
463
|
}> = Awaited<ReturnType<T["input"]>>["ctx"]["auth"];
|
|
421
464
|
//#endregion
|
|
422
|
-
export { AuthApi, AuthApiBase, AuthConfig, AuthCtx, AuthCtxConfig,
|
|
465
|
+
export { AuthApi, AuthApiBase, AuthConfig, AuthContext, AuthCtx, AuthCtxConfig, ConvexAuthResult, InferAuth, InferClientApi, UserDoc, createAuth };
|
|
423
466
|
//# 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":";;;;;;;;;;AAqCA;;KAHY,UAAA,GAAa,IAAA,CAAK,gBAAA;;KAGlB,OAAA,GAAU,GAAA;AAAA,KAEjB,0BAAA,wBACoB,uBAAA,gBACrB,IAAA,CACF,UAAA,QAAkB,MAAA;EAGlB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OACA,MAAA,WACG,OAAA;IACH,GAAA;MACE,IAAA,EAAM,oBAAA,GAAuB,QAAA;IAAA;IAE/B,IAAA;EAAA;AAAA;;;;;;;;AAtcJ;;;;;;;;;;;;;;;;;KAwhBY,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,9 +1,13 @@
|
|
|
1
|
-
import { AuthError } from "./authError.js";
|
|
2
1
|
import { Auth } from "./runtime.js";
|
|
3
|
-
import {
|
|
2
|
+
import { Cv } from "@robelest/fx/convex";
|
|
4
3
|
|
|
5
4
|
//#region src/server/auth.ts
|
|
6
5
|
/**
|
|
6
|
+
* Auth configuration helpers for Convex Auth.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
7
11
|
* Create an auth API object.
|
|
8
12
|
*
|
|
9
13
|
* When `new SSO()` is included in providers, `auth.sso` and `auth.scim`
|
|
@@ -37,9 +41,9 @@ import { Fx } from "@robelest/fx";
|
|
|
37
41
|
* 1. `user.id(ctx)` → userId or null (exit early)
|
|
38
42
|
* 2. `user.get(ctx, userId)` → user doc (cached per-execution)
|
|
39
43
|
* 3. `user.getActiveGroup(ctx, { userId })` → groupId or null
|
|
40
|
-
* 4. If groupId → `member.
|
|
44
|
+
* 4. If groupId → `member.inspect(ctx, { userId, groupId })` → role + grants
|
|
41
45
|
*/
|
|
42
|
-
async function
|
|
46
|
+
async function getAuthContext(auth, ctx) {
|
|
43
47
|
const userId = await auth.user.id(ctx);
|
|
44
48
|
if (!userId) return null;
|
|
45
49
|
const user = await auth.user.get(ctx, userId);
|
|
@@ -47,7 +51,7 @@ async function resolveAuthContext(auth, ctx) {
|
|
|
47
51
|
let role = null;
|
|
48
52
|
let grants = [];
|
|
49
53
|
if (groupId) {
|
|
50
|
-
const resolved = await auth.member.
|
|
54
|
+
const resolved = await auth.member.inspect(ctx, {
|
|
51
55
|
userId,
|
|
52
56
|
groupId
|
|
53
57
|
});
|
|
@@ -73,20 +77,32 @@ function createAuth(component, config) {
|
|
|
73
77
|
const { domain: domainApi, scim: scimApi, connection: connectionApi, audit: auditApi, webhook: webhookApi, oidc: oidcApi, saml: samlApi, ...restSso } = authResult.auth.sso;
|
|
74
78
|
const setEnterpriseDomains = async (ctx, enterpriseId, domains) => {
|
|
75
79
|
const enterprise = await connectionApi.get(ctx, enterpriseId);
|
|
76
|
-
if (enterprise === null) throw
|
|
80
|
+
if (enterprise === null) throw Cv.error({
|
|
81
|
+
code: "INVALID_PARAMETERS",
|
|
82
|
+
message: "Enterprise not found."
|
|
83
|
+
});
|
|
77
84
|
const normalized = domains.map((entry) => ({
|
|
78
85
|
...entry,
|
|
79
86
|
domain: entry.domain.trim().toLowerCase()
|
|
80
87
|
}));
|
|
81
88
|
const deduped = /* @__PURE__ */ new Map();
|
|
82
89
|
for (const entry of normalized) {
|
|
83
|
-
if (entry.domain.length === 0) throw
|
|
84
|
-
|
|
90
|
+
if (entry.domain.length === 0) throw Cv.error({
|
|
91
|
+
code: "INVALID_PARAMETERS",
|
|
92
|
+
message: "Domain must not be empty."
|
|
93
|
+
});
|
|
94
|
+
if (deduped.has(entry.domain)) throw Cv.error({
|
|
95
|
+
code: "INVALID_PARAMETERS",
|
|
96
|
+
message: `Duplicate domain: ${entry.domain}`
|
|
97
|
+
});
|
|
85
98
|
deduped.set(entry.domain, entry);
|
|
86
99
|
}
|
|
87
100
|
const nextDomains = [...deduped.values()];
|
|
88
101
|
const primaryCount = nextDomains.filter((entry) => entry.isPrimary).length;
|
|
89
|
-
if (primaryCount > 1) throw
|
|
102
|
+
if (primaryCount > 1) throw Cv.error({
|
|
103
|
+
code: "INVALID_PARAMETERS",
|
|
104
|
+
message: "Only one primary domain may be set."
|
|
105
|
+
});
|
|
90
106
|
if (nextDomains.length > 0 && primaryCount === 0) nextDomains[0] = {
|
|
91
107
|
...nextDomains[0],
|
|
92
108
|
isPrimary: true
|
|
@@ -110,7 +126,6 @@ function createAuth(component, config) {
|
|
|
110
126
|
});
|
|
111
127
|
}
|
|
112
128
|
return {
|
|
113
|
-
ok: true,
|
|
114
129
|
enterpriseId,
|
|
115
130
|
domains: (await domainApi.list(ctx, enterpriseId)).map((domain) => ({
|
|
116
131
|
domainId: domain._id,
|
|
@@ -169,12 +184,24 @@ function createAuth(component, config) {
|
|
|
169
184
|
validate: scimApi.validate
|
|
170
185
|
} },
|
|
171
186
|
http: authResult.auth.http,
|
|
172
|
-
|
|
187
|
+
context: async (ctx) => {
|
|
188
|
+
const authContext = await getAuthContext(authResult.auth, ctx);
|
|
189
|
+
if (authContext === null) throw Cv.error({
|
|
190
|
+
code: "NOT_SIGNED_IN",
|
|
191
|
+
message: "Authentication required."
|
|
192
|
+
});
|
|
193
|
+
return authContext;
|
|
194
|
+
},
|
|
173
195
|
ctx: () => ({
|
|
174
196
|
args: {},
|
|
175
197
|
input: async (ctx) => {
|
|
198
|
+
const authCtx = await getAuthContext(authResult.auth, ctx);
|
|
199
|
+
if (authCtx === null) throw Cv.error({
|
|
200
|
+
code: "NOT_SIGNED_IN",
|
|
201
|
+
message: "Authentication required."
|
|
202
|
+
});
|
|
176
203
|
return {
|
|
177
|
-
ctx: { auth:
|
|
204
|
+
ctx: { auth: authCtx },
|
|
178
205
|
args: {}
|
|
179
206
|
};
|
|
180
207
|
}
|
|
@@ -186,39 +213,32 @@ function AuthCtx(auth, config) {
|
|
|
186
213
|
args: {},
|
|
187
214
|
input: async (ctx, _args, _extra) => {
|
|
188
215
|
const nativeAuth = ctx.auth;
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
userId: null,
|
|
212
|
-
user: null
|
|
213
|
-
} },
|
|
214
|
-
args: {}
|
|
215
|
-
};
|
|
216
|
-
const extra = config?.resolve ? await config.resolve(ctx, userContext.user) : {};
|
|
216
|
+
const getUserIdentity = nativeAuth.getUserIdentity.bind(nativeAuth);
|
|
217
|
+
const fallback = () => getAuthContext(auth, ctx);
|
|
218
|
+
const authOverride = config?.authResolve ? await config.authResolve(ctx, fallback) : void 0;
|
|
219
|
+
const resolved = authOverride === void 0 ? await fallback() : authOverride;
|
|
220
|
+
if (resolved === null) {
|
|
221
|
+
if (config?.optional !== true) throw Cv.error({
|
|
222
|
+
code: "NOT_SIGNED_IN",
|
|
223
|
+
message: "Authentication required."
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
ctx: { auth: {
|
|
227
|
+
getUserIdentity,
|
|
228
|
+
userId: null,
|
|
229
|
+
user: null,
|
|
230
|
+
groupId: null,
|
|
231
|
+
role: null,
|
|
232
|
+
grants: []
|
|
233
|
+
} },
|
|
234
|
+
args: {}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const extra = config?.resolve ? await config.resolve(ctx, resolved.user, resolved) : {};
|
|
217
238
|
return {
|
|
218
239
|
ctx: { auth: {
|
|
219
|
-
getUserIdentity
|
|
220
|
-
|
|
221
|
-
user: userContext.user,
|
|
240
|
+
getUserIdentity,
|
|
241
|
+
...resolved,
|
|
222
242
|
...extra
|
|
223
243
|
} },
|
|
224
244
|
args: {}
|