@robelest/convex-auth 0.0.4-preview.29 → 0.0.4-preview.30
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/bin.js +34 -1
- package/dist/browser/passkey.js +2 -2
- package/dist/client/core/types.d.ts +4 -15
- package/dist/client/factors/device.js +3 -3
- package/dist/client/factors/totp.js +8 -8
- package/dist/client/index.js +7 -7
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/model.d.ts +25 -25
- package/dist/component/schema.d.ts +289 -289
- package/dist/core/index.d.ts +5 -24
- package/dist/core/index.js +3 -16
- package/dist/server/auth-context.d.ts +1 -1
- package/dist/server/auth-context.js +14 -1
- package/dist/server/auth.d.ts +3 -17
- package/dist/server/auth.js +2 -7
- package/dist/server/config.js +10 -0
- package/dist/server/context.js +2 -4
- package/dist/server/contract.d.ts +1 -1
- package/dist/server/convexIdentity.d.ts +15 -0
- package/dist/server/convexIdentity.js +1 -0
- package/dist/server/core.js +0 -13
- package/dist/server/device.js +13 -12
- package/dist/server/env.js +10 -2
- package/dist/server/http.d.ts +1 -1
- package/dist/server/identity.js +30 -4
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/mounts.d.ts +79 -79
- package/dist/server/mutations/refresh.js +38 -7
- package/dist/server/mutations/signin.js +12 -2
- package/dist/server/mutations/signout.js +27 -10
- package/dist/server/mutations/store.js +1 -1
- package/dist/server/oauth/factory.js +2 -1
- package/dist/server/passkey.js +12 -13
- package/dist/server/prefetch.js +8 -8
- package/dist/server/runtime.d.ts +19 -25
- package/dist/server/runtime.js +7 -40
- package/dist/server/sessions.d.ts +2 -1
- package/dist/server/sessions.js +21 -11
- package/dist/server/signin.js +17 -16
- package/dist/server/sso/domain.d.ts +1 -1
- package/dist/server/telemetry.js +58 -0
- package/dist/server/tokens.js +24 -4
- package/dist/server/totp.js +13 -11
- package/dist/server/types.d.ts +58 -2
- package/dist/server/utils/span.js +10 -1
- package/dist/shared/authResults.d.ts +16 -0
- package/package.json +6 -3
- package/dist/server/constants.js +0 -6
package/dist/core/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { ComponentCtx, ComponentReadCtx } from "../server/componentContext.js";
|
|
2
1
|
import { AuthAuthorizationConfig, ConvexAuthConfig, Doc, KeyDoc, KeyScope, ScopeChecker, UserOrderBy, UserWhere } from "../server/types.js";
|
|
2
|
+
import { AuthConfig, AuthContext, AuthContextConfig, AuthContextFactory, AuthContextResolver, OptionalAuthContext, UserDoc } from "../server/auth-context.js";
|
|
3
|
+
import { ComponentCtx, ComponentReadCtx } from "../server/componentContext.js";
|
|
3
4
|
import { AuthProfile } from "../server/payloads.js";
|
|
4
|
-
import { AuthConfig, AuthContext, AuthContextConfig, AuthContextFactory as AuthContextFactory$1, AuthContextResolver as AuthContextResolver$1, OptionalAuthContext, UserDoc } from "../server/auth-context.js";
|
|
5
5
|
import "../component/index.js";
|
|
6
|
+
import "../server/convexIdentity.js";
|
|
6
7
|
import * as convex_values0 from "convex/values";
|
|
7
8
|
import * as convex_server0 from "convex/server";
|
|
8
9
|
import * as fluent_convex0 from "fluent-convex";
|
|
9
10
|
|
|
10
11
|
//#region src/core/index.d.ts
|
|
11
|
-
type AuthContextResolver = AuthContextResolver$1;
|
|
12
|
-
type AuthContextFactory = AuthContextFactory$1;
|
|
13
12
|
/**
|
|
14
13
|
* Create a lightweight auth context object.
|
|
15
14
|
*
|
|
@@ -36,6 +35,8 @@ type AuthContextFactory = AuthContextFactory$1;
|
|
|
36
35
|
declare function createAuthContext(component: ConvexAuthConfig["component"], config?: Omit<AuthConfig, "providers"> & {
|
|
37
36
|
authorization?: AuthAuthorizationConfig;
|
|
38
37
|
}): {
|
|
38
|
+
context: AuthContextResolver;
|
|
39
|
+
ctx: AuthContextFactory;
|
|
39
40
|
user: {
|
|
40
41
|
get: {
|
|
41
42
|
(ctx: ComponentReadCtx, userId: string): Promise<Doc<"User"> | null>;
|
|
@@ -74,12 +75,6 @@ declare function createAuthContext(component: ConvexAuthConfig["component"], con
|
|
|
74
75
|
}>;
|
|
75
76
|
};
|
|
76
77
|
session: {
|
|
77
|
-
current: (ctx: {
|
|
78
|
-
auth: convex_server0.Auth;
|
|
79
|
-
}) => Promise<convex_values0.GenericId<"Session"> | null>;
|
|
80
|
-
userId: (ctx: {
|
|
81
|
-
auth: convex_server0.Auth;
|
|
82
|
-
}) => Promise<convex_values0.GenericId<"User"> | null>;
|
|
83
78
|
invalidate: <DataModel extends fluent_convex0.GenericDataModel>(ctx: convex_server0.GenericActionCtx<DataModel>, args: {
|
|
84
79
|
userId: convex_values0.GenericId<"User">;
|
|
85
80
|
except?: convex_values0.GenericId<"Session">[];
|
|
@@ -396,20 +391,6 @@ declare function createAuthContext(component: ConvexAuthConfig["component"], con
|
|
|
396
391
|
secret: string;
|
|
397
392
|
}>;
|
|
398
393
|
};
|
|
399
|
-
/**
|
|
400
|
-
* Zero-round-trip helper: parse the current user id straight from the
|
|
401
|
-
* JWT subject claim. No component read, no cache lookup — just the
|
|
402
|
-
* identity token. Returns `null` when unauthenticated.
|
|
403
|
-
*
|
|
404
|
-
* Prefer this over `auth.context(ctx)` when you only need the user's
|
|
405
|
-
* id (e.g. early guards, routing decisions, audit logging). For the
|
|
406
|
-
* full user document, follow up with `auth.user.get(ctx, userId)`.
|
|
407
|
-
*/
|
|
408
|
-
getUserId: (ctx: {
|
|
409
|
-
auth: convex_server0.Auth;
|
|
410
|
-
}) => Promise<convex_values0.GenericId<"User"> | null>;
|
|
411
|
-
context: AuthContextResolver;
|
|
412
|
-
ctx: AuthContextFactory;
|
|
413
394
|
};
|
|
414
395
|
//#endregion
|
|
415
396
|
export { type AuthContext, type AuthContextConfig, type OptionalAuthContext, type UserDoc, createAuthContext };
|
package/dist/core/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../server/convexIdentity.js";
|
|
2
|
+
import { createAuthContextFacade } from "../server/auth-context.js";
|
|
2
3
|
import { configDefaults } from "../server/config.js";
|
|
3
4
|
import { createCoreDomains } from "../server/core.js";
|
|
4
5
|
import { callModifyAccount } from "../server/mutations/account.js";
|
|
@@ -8,15 +9,6 @@ import { callRetrieveAccountWithCredentials } from "../server/mutations/retrieve
|
|
|
8
9
|
|
|
9
10
|
//#region src/core/index.ts
|
|
10
11
|
/**
|
|
11
|
-
* Lightweight auth context entry point for `@robelest/convex-auth/core`.
|
|
12
|
-
*
|
|
13
|
-
* Provides auth context resolution, user/session/member/group lookups,
|
|
14
|
-
* and authorization helpers without pulling in provider implementations,
|
|
15
|
-
* OAuth, crypto, or sign-in logic.
|
|
16
|
-
*
|
|
17
|
-
* @module
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
12
|
* Create a lightweight auth context object.
|
|
21
13
|
*
|
|
22
14
|
* Returns the same `user`, `session`, `member`, `group`, `account`,
|
|
@@ -70,12 +62,7 @@ function createAuthContext(component, config) {
|
|
|
70
62
|
member: domains.member,
|
|
71
63
|
invite: domains.invite,
|
|
72
64
|
key: domains.key,
|
|
73
|
-
|
|
74
|
-
context: ((ctx, config$1) => {
|
|
75
|
-
assertAuthResolverContext(ctx);
|
|
76
|
-
return createPublicAuthContext(authLike, ctx, config$1);
|
|
77
|
-
}),
|
|
78
|
-
ctx: ((config$1) => createAuthContextCustomization(authLike, config$1))
|
|
65
|
+
...createAuthContextFacade(authLike)
|
|
79
66
|
};
|
|
80
67
|
}
|
|
81
68
|
|
|
@@ -160,7 +160,7 @@ type AuthContextConfig<TResolve extends Record<string, unknown> = Record<string,
|
|
|
160
160
|
* Attach additional derived fields to the auth context after the base auth
|
|
161
161
|
* context is resolved.
|
|
162
162
|
*
|
|
163
|
-
* This callback runs only when
|
|
163
|
+
* This callback runs only when an authenticated user context is available.
|
|
164
164
|
*/
|
|
165
165
|
resolve?: (ctx: TCtx, user: UserDoc, auth: AuthContext) => Promise<TResolve> | TResolve;
|
|
166
166
|
/**
|
|
@@ -70,7 +70,20 @@ function createAuthContextCustomization(auth, config) {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Build the shared public auth-context facade used by both `createAuth()` and
|
|
75
|
+
* `createAuthContext()`.
|
|
76
|
+
*/
|
|
77
|
+
function createAuthContextFacade(auth) {
|
|
78
|
+
return {
|
|
79
|
+
context: ((ctx, config) => {
|
|
80
|
+
assertAuthResolverContext(ctx);
|
|
81
|
+
return createPublicAuthContext(auth, ctx, config);
|
|
82
|
+
}),
|
|
83
|
+
ctx: ((config) => createAuthContextCustomization(auth, config))
|
|
84
|
+
};
|
|
85
|
+
}
|
|
73
86
|
|
|
74
87
|
//#endregion
|
|
75
|
-
export {
|
|
88
|
+
export { createAuthContextCustomization, createAuthContextFacade, createPublicAuthContext };
|
|
76
89
|
//# sourceMappingURL=auth-context.js.map
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -72,28 +72,14 @@ type AuthApiBase<TAuthorization extends AuthAuthorizationConfig | undefined = un
|
|
|
72
72
|
invite: ReturnType<typeof Auth>["auth"]["invite"];
|
|
73
73
|
key: ReturnType<typeof Auth>["auth"]["key"];
|
|
74
74
|
http: ReturnType<typeof Auth>["auth"]["http"];
|
|
75
|
-
/**
|
|
76
|
-
* Zero-round-trip helper: parse the current user id from the JWT subject
|
|
77
|
-
* claim. No component read, no cache lookup. Returns `null` when
|
|
78
|
-
* unauthenticated.
|
|
79
|
-
*
|
|
80
|
-
* Prefer this over `auth.context(ctx)` when a handler only needs the
|
|
81
|
-
* user's id (audit logging, early guards, routing). For the full user
|
|
82
|
-
* document, follow up with `auth.user.get(ctx, userId)` — cached per
|
|
83
|
-
* request.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const userId = await auth.getUserId(ctx);
|
|
88
|
-
* if (!userId) throw new Error("Not signed in");
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
getUserId: ReturnType<typeof Auth>["auth"]["session"]["userId"];
|
|
92
75
|
/**
|
|
93
76
|
* Resolve the current request's auth context. Framework-agnostic — use
|
|
94
77
|
* this in fluent-convex middleware, custom wrappers, or anywhere you
|
|
95
78
|
* need the current `{ userId, user, groupId, role, grants }` object.
|
|
96
79
|
*
|
|
80
|
+
* This is the authorization-enrichment path. For native identity claims
|
|
81
|
+
* already present on the JWT, prefer `ctx.auth.getUserIdentity()`.
|
|
82
|
+
*
|
|
97
83
|
* Throws a structured `ConvexError` when unauthenticated by default.
|
|
98
84
|
* Pass `{ optional: true }` to get a null-shaped auth object instead.
|
|
99
85
|
*
|
package/dist/server/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAuthContextCustomization, createAuthContextFacade, createPublicAuthContext } from "./auth-context.js";
|
|
2
2
|
import { Auth } from "./runtime.js";
|
|
3
3
|
import { ConvexError } from "convex/values";
|
|
4
4
|
|
|
@@ -145,12 +145,7 @@ function createAuth(component, config) {
|
|
|
145
145
|
invite: authResult.auth.invite,
|
|
146
146
|
key: authResult.auth.key,
|
|
147
147
|
http: authResult.auth.http,
|
|
148
|
-
|
|
149
|
-
context: ((ctx, config$1) => {
|
|
150
|
-
assertAuthResolverContext(ctx);
|
|
151
|
-
return createPublicAuthContext(authResult.auth, ctx, config$1);
|
|
152
|
-
}),
|
|
153
|
-
ctx: ((config$1) => createAuthContextCustomization(authResult.auth, config$1))
|
|
148
|
+
...createAuthContextFacade(authResult.auth)
|
|
154
149
|
};
|
|
155
150
|
}
|
|
156
151
|
|
package/dist/server/config.js
CHANGED
|
@@ -8,6 +8,7 @@ function configDefaults(config_) {
|
|
|
8
8
|
return {
|
|
9
9
|
...config,
|
|
10
10
|
authorization: normalizeAuthorizationConfig(config.authorization),
|
|
11
|
+
telemetry: normalizeTelemetryConfig(config.telemetry),
|
|
11
12
|
extraProviders: materializeProviders(extraProviders)
|
|
12
13
|
};
|
|
13
14
|
}
|
|
@@ -54,6 +55,15 @@ function normalizeAuthorizationConfig(authorization) {
|
|
|
54
55
|
grants: Array.from(new Set(role.grants)).sort()
|
|
55
56
|
}])) };
|
|
56
57
|
}
|
|
58
|
+
function normalizeTelemetryConfig(telemetry) {
|
|
59
|
+
const normalized = {
|
|
60
|
+
includeIdentity: telemetry?.includeIdentity ?? "none",
|
|
61
|
+
identityFields: telemetry?.identityFields ?? {},
|
|
62
|
+
...telemetry?.hashIdentity ? { hashIdentity: telemetry.hashIdentity } : {}
|
|
63
|
+
};
|
|
64
|
+
if (normalized.includeIdentity === "hashed" && normalized.hashIdentity === void 0) throw new Error("Convex Auth telemetry with `includeIdentity: \"hashed\"` requires a `hashIdentity` function.");
|
|
65
|
+
return normalized;
|
|
66
|
+
}
|
|
57
67
|
|
|
58
68
|
//#endregion
|
|
59
69
|
export { configDefaults, listAvailableProviders };
|
package/dist/server/context.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAuthenticatedUserIdOrNull } from "./identity.js";
|
|
2
2
|
|
|
3
3
|
//#region src/server/context.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
async function getSessionUserId(ctx) {
|
|
6
|
-
|
|
7
|
-
if (identity === null) return null;
|
|
8
|
-
return userIdFromIdentitySubject(identity.subject);
|
|
6
|
+
return await getAuthenticatedUserIdOrNull(ctx);
|
|
9
7
|
}
|
|
10
8
|
/** @internal */
|
|
11
9
|
async function getAuthContextForUser(auth, ctx, userId, opts) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenericId } from "convex/values";
|
|
2
|
+
|
|
3
|
+
//#region src/server/convexIdentity.d.ts
|
|
4
|
+
declare module "convex/server" {
|
|
5
|
+
interface UserIdentity {
|
|
6
|
+
/**
|
|
7
|
+
* Current session id issued by convex-auth.
|
|
8
|
+
*
|
|
9
|
+
* This is a custom JWT claim mirrored into Convex's identity object so
|
|
10
|
+
* native identity access can read `identity.sid` directly.
|
|
11
|
+
*/
|
|
12
|
+
readonly sid?: GenericId<"Session">;
|
|
13
|
+
}
|
|
14
|
+
} //# sourceMappingURL=convexIdentity.d.ts.map
|
|
15
|
+
//# sourceMappingURL=convexIdentity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/server/core.js
CHANGED
|
@@ -2,7 +2,6 @@ import { getSessionUserId } from "./context.js";
|
|
|
2
2
|
import { cached, ctxCacheHas, invalidateCtxCache } from "./ctxCache.js";
|
|
3
3
|
import { generateRandomString, sha256 } from "./random.js";
|
|
4
4
|
import { buildScopeChecker, checkKeyRateLimit, generateApiKey, hashApiKey } from "./keys.js";
|
|
5
|
-
import { TOKEN_SUB_CLAIM_DIVIDER } from "./constants.js";
|
|
6
5
|
import { ConvexError } from "convex/values";
|
|
7
6
|
|
|
8
7
|
//#region src/server/core.ts
|
|
@@ -119,18 +118,6 @@ function createCoreDomains(deps) {
|
|
|
119
118
|
}
|
|
120
119
|
};
|
|
121
120
|
const session = {
|
|
122
|
-
current: async (ctx) => {
|
|
123
|
-
const identity = await ctx.auth.getUserIdentity();
|
|
124
|
-
if (identity === null) return null;
|
|
125
|
-
const [, sessionId] = identity.subject.split(TOKEN_SUB_CLAIM_DIVIDER);
|
|
126
|
-
return sessionId;
|
|
127
|
-
},
|
|
128
|
-
userId: async (ctx) => {
|
|
129
|
-
const identity = await ctx.auth.getUserIdentity();
|
|
130
|
-
if (identity === null) return null;
|
|
131
|
-
const [userId] = identity.subject.split(TOKEN_SUB_CLAIM_DIVIDER);
|
|
132
|
-
return userId ?? null;
|
|
133
|
-
},
|
|
134
121
|
invalidate: async (ctx, args) => {
|
|
135
122
|
await callInvalidateSessions(ctx, args);
|
|
136
123
|
return {
|
package/dist/server/device.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAuthenticatedUserIdOrNull } from "./identity.js";
|
|
2
2
|
import { generateRandomString, sha256 } from "./random.js";
|
|
3
3
|
import { requireEnv } from "./env.js";
|
|
4
4
|
import { callSignIn } from "./mutations/signin.js";
|
|
@@ -39,12 +39,14 @@ async function handleCreate(ctx, provider) {
|
|
|
39
39
|
const verificationUri = provider.verificationUri ?? `${process.env.SITE_URL ?? requireEnv("SITE_URL")}/device`;
|
|
40
40
|
return {
|
|
41
41
|
kind: "deviceCode",
|
|
42
|
-
deviceCode
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
deviceCode: {
|
|
43
|
+
deviceCode,
|
|
44
|
+
userCode,
|
|
45
|
+
verificationUri,
|
|
46
|
+
verificationUriComplete: `${verificationUri}?code=${encodeURIComponent(userCode)}`,
|
|
47
|
+
expiresIn: provider.expiresIn,
|
|
48
|
+
interval: provider.interval
|
|
49
|
+
}
|
|
48
50
|
};
|
|
49
51
|
}
|
|
50
52
|
async function handlePoll(ctx, params) {
|
|
@@ -66,7 +68,7 @@ async function handlePoll(ctx, params) {
|
|
|
66
68
|
await mutateDeviceDelete(ctx, doc._id);
|
|
67
69
|
return {
|
|
68
70
|
kind: "signedIn",
|
|
69
|
-
|
|
71
|
+
session: await callSignIn(ctx, {
|
|
70
72
|
userId: doc.userId,
|
|
71
73
|
sessionId: doc.sessionId,
|
|
72
74
|
generateTokens: true
|
|
@@ -75,9 +77,8 @@ async function handlePoll(ctx, params) {
|
|
|
75
77
|
}
|
|
76
78
|
async function handleDeviceVerify(ctx, params) {
|
|
77
79
|
if (typeof params.userCode !== "string") throw deviceError("DEVICE_INVALID_USER_CODE", "Missing `userCode` parameter for verify flow.");
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
const userId = userIdFromIdentitySubject(identity.subject);
|
|
80
|
+
const userId = await getAuthenticatedUserIdOrNull(ctx);
|
|
81
|
+
if (userId === null) throw deviceError("NOT_SIGNED_IN", "You must be signed in to authorize a device.");
|
|
81
82
|
const doc = await queryDeviceByUserCode(ctx, params.userCode);
|
|
82
83
|
if (doc === null) throw deviceError("DEVICE_INVALID_USER_CODE", "Invalid or expired user code.");
|
|
83
84
|
if (Date.now() > doc.expiresAt) {
|
|
@@ -92,7 +93,7 @@ async function handleDeviceVerify(ctx, params) {
|
|
|
92
93
|
await mutateDeviceAuthorize(ctx, doc._id, signInResult.userId, signInResult.sessionId);
|
|
93
94
|
return {
|
|
94
95
|
kind: "signedIn",
|
|
95
|
-
|
|
96
|
+
session: null
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** @internal */
|
package/dist/server/env.js
CHANGED
|
@@ -5,12 +5,20 @@ function readEnv(name) {
|
|
|
5
5
|
const value = typeof process === "undefined" ? void 0 : process.env?.[name];
|
|
6
6
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
7
7
|
}
|
|
8
|
+
function missingEnvMessage(name) {
|
|
9
|
+
switch (name) {
|
|
10
|
+
case "JWT_PRIVATE_KEY":
|
|
11
|
+
case "JWKS":
|
|
12
|
+
case "AUTH_SECRET_ENCRYPTION_KEY": return `Missing environment variable \`${name}\`. Run the convex-auth setup wizard to generate and configure auth keys.`;
|
|
13
|
+
default: return `Missing environment variable \`${name}\``;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
8
16
|
/** @internal */
|
|
9
17
|
const readConfigSync = (value) => value;
|
|
10
18
|
/** @internal */
|
|
11
19
|
const envString = (name) => {
|
|
12
20
|
const value = readEnv(name);
|
|
13
|
-
if (value === void 0) throw new Error(
|
|
21
|
+
if (value === void 0) throw new Error(missingEnvMessage(name));
|
|
14
22
|
return value;
|
|
15
23
|
};
|
|
16
24
|
/** @internal */
|
|
@@ -38,7 +46,7 @@ function requireEnv(name) {
|
|
|
38
46
|
} catch {
|
|
39
47
|
throw new ConvexError({
|
|
40
48
|
code: "MISSING_ENV_VAR",
|
|
41
|
-
message:
|
|
49
|
+
message: missingEnvMessage(name)
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
52
|
}
|
package/dist/server/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComponentReadCtx } from "./componentContext.js";
|
|
2
1
|
import { HttpKeyContext } from "./types.js";
|
|
3
2
|
import { AuthContext, OptionalAuthContext, UserDoc } from "./auth-context.js";
|
|
3
|
+
import { ComponentReadCtx } from "./componentContext.js";
|
|
4
4
|
import "./auth.js";
|
|
5
5
|
import { GenericActionCtx, GenericDataModel, HttpRouter, UserIdentity } from "convex/server";
|
|
6
6
|
|
package/dist/server/identity.js
CHANGED
|
@@ -3,14 +3,40 @@ import { ConvexError } from "convex/values";
|
|
|
3
3
|
//#region src/server/identity.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
function userIdFromIdentitySubject(subject) {
|
|
6
|
-
|
|
7
|
-
if (typeof userId !== "string" || userId.length === 0 || rest.length === 0 || rest.some((segment) => segment.length === 0)) throw new ConvexError({
|
|
6
|
+
if (typeof subject !== "string" || subject.length === 0) throw new ConvexError({
|
|
8
7
|
code: "INTERNAL_ERROR",
|
|
9
8
|
message: "Authenticated identity subject is malformed."
|
|
10
9
|
});
|
|
11
|
-
return
|
|
10
|
+
return subject;
|
|
11
|
+
}
|
|
12
|
+
/** @internal */
|
|
13
|
+
function userIdFromIdentity(identity) {
|
|
14
|
+
return userIdFromIdentitySubject(identity.subject);
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
function sessionIdFromIdentity(identity) {
|
|
18
|
+
const sessionId = identity.sid;
|
|
19
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) throw new ConvexError({
|
|
20
|
+
code: "INTERNAL_ERROR",
|
|
21
|
+
message: "Authenticated identity is missing a session id claim."
|
|
22
|
+
});
|
|
23
|
+
return sessionId;
|
|
24
|
+
}
|
|
25
|
+
/** @internal */
|
|
26
|
+
async function getUserIdentityOrNull(ctx) {
|
|
27
|
+
return await ctx.auth.getUserIdentity();
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
async function getAuthenticatedUserIdOrNull(ctx) {
|
|
31
|
+
const identity = await getUserIdentityOrNull(ctx);
|
|
32
|
+
return identity === null ? null : userIdFromIdentity(identity);
|
|
33
|
+
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
async function getAuthenticatedSessionIdOrNull(ctx) {
|
|
36
|
+
const identity = await getUserIdentityOrNull(ctx);
|
|
37
|
+
return identity === null ? null : sessionIdFromIdentity(identity);
|
|
12
38
|
}
|
|
13
39
|
|
|
14
40
|
//#endregion
|
|
15
|
-
export {
|
|
41
|
+
export { getAuthenticatedSessionIdOrNull, getAuthenticatedUserIdOrNull };
|
|
16
42
|
//# sourceMappingURL=identity.js.map
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthConfig, AuthContext, AuthContextConfig, InferAuth, OptionalAuthContext, UserDoc } from "./auth-context.js";
|
|
2
2
|
import { HttpAuthContext, HttpAuthContextConfig, OptionalHttpAuthContext } from "./http.js";
|
|
3
3
|
import { AuthApi, AuthApiBase, ConvexAuthResult, InferClientApi, createAuth } from "./auth.js";
|
|
4
|
+
import "./convexIdentity.js";
|
|
4
5
|
import { CreateAuthGroupSsoOptions, GroupSsoAccessHandler, GroupSsoAccessInput, GroupSsoAccessPermissions, GroupSsoPermission, GroupSsoResolvedAccessHandler, createAuthGroupSso, scim, sso } from "./mounts.js";
|
|
5
6
|
import { AuthCookie, AuthCookieConfig, AuthCookies, RefreshResult, ServerOptions, authCookieNames, parseAuthCookies, serializeAuthCookies, server, shouldProxyAuthAction, structuredAuthCookies } from "./prefetch.js";
|
|
6
7
|
export { type AuthApi, type AuthApiBase, type AuthConfig, type AuthContext, type AuthContextConfig, type AuthCookie, type AuthCookieConfig, type AuthCookies, type ConvexAuthResult, type CreateAuthGroupSsoOptions, type GroupSsoAccessHandler, type GroupSsoAccessInput, type GroupSsoAccessPermissions, type GroupSsoPermission, type GroupSsoResolvedAccessHandler, type HttpAuthContext, type HttpAuthContextConfig, type InferAuth, type InferClientApi, type OptionalAuthContext, type OptionalHttpAuthContext, type RefreshResult, type ServerOptions, type UserDoc, authCookieNames, createAuth, createAuthGroupSso, parseAuthCookies, scim, serializeAuthCookies, server, shouldProxyAuthAction, sso, structuredAuthCookies };
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./convexIdentity.js";
|
|
1
2
|
import { createAuth } from "./auth.js";
|
|
2
3
|
import { createAuthGroupSso, scim, sso } from "./mounts.js";
|
|
3
4
|
import { authCookieNames, parseAuthCookies, serializeAuthCookies, server, shouldProxyAuthAction, structuredAuthCookies } from "./prefetch.js";
|