@robelest/convex-auth 0.0.2 → 0.0.3-preview.1
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.cjs +1 -1
- package/dist/client/index.d.ts +33 -9
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +79 -13
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/component.d.ts +48 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/index.d.ts +10 -4
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/index.js +8 -3
- package/dist/component/index.js.map +1 -1
- package/dist/component/public.d.ts +163 -3
- package/dist/component/public.d.ts.map +1 -1
- package/dist/component/public.js +124 -0
- package/dist/component/public.js.map +1 -1
- package/dist/component/schema.d.ts +81 -2
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +45 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/providers/anonymous.d.ts +3 -0
- package/dist/providers/anonymous.d.ts.map +1 -1
- package/dist/providers/anonymous.js +3 -0
- package/dist/providers/anonymous.js.map +1 -1
- package/dist/providers/credentials.d.ts +3 -0
- package/dist/providers/credentials.d.ts.map +1 -1
- package/dist/providers/credentials.js +3 -0
- package/dist/providers/credentials.js.map +1 -1
- package/dist/providers/email.d.ts +3 -0
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +3 -0
- package/dist/providers/email.js.map +1 -1
- package/dist/providers/passkey.d.ts +7 -1
- package/dist/providers/passkey.d.ts.map +1 -1
- package/dist/providers/passkey.js +7 -1
- package/dist/providers/passkey.js.map +1 -1
- package/dist/providers/password.d.ts +3 -0
- package/dist/providers/password.d.ts.map +1 -1
- package/dist/providers/password.js +3 -0
- package/dist/providers/password.js.map +1 -1
- package/dist/providers/phone.d.ts +3 -0
- package/dist/providers/phone.d.ts.map +1 -1
- package/dist/providers/phone.js +3 -0
- package/dist/providers/phone.js.map +1 -1
- package/dist/providers/totp.d.ts +8 -0
- package/dist/providers/totp.d.ts.map +1 -1
- package/dist/providers/totp.js +8 -0
- package/dist/providers/totp.js.map +1 -1
- package/dist/server/convex-auth.d.ts +185 -25
- package/dist/server/convex-auth.d.ts.map +1 -1
- package/dist/server/convex-auth.js +317 -58
- package/dist/server/convex-auth.js.map +1 -1
- package/dist/server/email-templates.d.ts +18 -0
- package/dist/server/email-templates.d.ts.map +1 -0
- package/dist/server/email-templates.js +74 -0
- package/dist/server/email-templates.js.map +1 -0
- package/dist/server/errors.d.ts +146 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +176 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/implementation/apiKey.d.ts +74 -0
- package/dist/server/implementation/apiKey.d.ts.map +1 -0
- package/dist/server/implementation/apiKey.js +139 -0
- package/dist/server/implementation/apiKey.js.map +1 -0
- package/dist/server/implementation/index.d.ts +151 -14
- package/dist/server/implementation/index.d.ts.map +1 -1
- package/dist/server/implementation/index.js +216 -24
- package/dist/server/implementation/index.js.map +1 -1
- package/dist/server/implementation/mutations/createAccountFromCredentials.d.ts.map +1 -1
- package/dist/server/implementation/mutations/createAccountFromCredentials.js +2 -1
- package/dist/server/implementation/mutations/createAccountFromCredentials.js.map +1 -1
- package/dist/server/implementation/mutations/createVerificationCode.d.ts +2 -2
- package/dist/server/implementation/mutations/index.d.ts +6 -6
- package/dist/server/implementation/mutations/modifyAccount.d.ts.map +1 -1
- package/dist/server/implementation/mutations/modifyAccount.js +2 -1
- package/dist/server/implementation/mutations/modifyAccount.js.map +1 -1
- package/dist/server/implementation/mutations/userOAuth.d.ts.map +1 -1
- package/dist/server/implementation/mutations/userOAuth.js +2 -1
- package/dist/server/implementation/mutations/userOAuth.js.map +1 -1
- package/dist/server/implementation/mutations/verifierSignature.d.ts.map +1 -1
- package/dist/server/implementation/mutations/verifierSignature.js +2 -1
- package/dist/server/implementation/mutations/verifierSignature.js.map +1 -1
- package/dist/server/implementation/passkey.d.ts.map +1 -1
- package/dist/server/implementation/passkey.js +28 -29
- package/dist/server/implementation/passkey.js.map +1 -1
- package/dist/server/implementation/provider.d.ts.map +1 -1
- package/dist/server/implementation/provider.js +5 -4
- package/dist/server/implementation/provider.js.map +1 -1
- package/dist/server/implementation/redirects.d.ts.map +1 -1
- package/dist/server/implementation/redirects.js +2 -1
- package/dist/server/implementation/redirects.js.map +1 -1
- package/dist/server/implementation/refreshTokens.d.ts.map +1 -1
- package/dist/server/implementation/refreshTokens.js +2 -1
- package/dist/server/implementation/refreshTokens.js.map +1 -1
- package/dist/server/implementation/signIn.d.ts.map +1 -1
- package/dist/server/implementation/signIn.js +8 -18
- package/dist/server/implementation/signIn.js.map +1 -1
- package/dist/server/implementation/totp.d.ts.map +1 -1
- package/dist/server/implementation/totp.js +16 -17
- package/dist/server/implementation/totp.js.map +1 -1
- package/dist/server/implementation/users.d.ts.map +1 -1
- package/dist/server/implementation/users.js +3 -2
- package/dist/server/implementation/users.js.map +1 -1
- package/dist/server/index.d.ts +157 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +180 -17
- package/dist/server/index.js.map +1 -1
- package/dist/server/oauth/authorizationUrl.d.ts.map +1 -1
- package/dist/server/oauth/authorizationUrl.js +2 -1
- package/dist/server/oauth/authorizationUrl.js.map +1 -1
- package/dist/server/oauth/callback.d.ts.map +1 -1
- package/dist/server/oauth/callback.js +5 -4
- package/dist/server/oauth/callback.js.map +1 -1
- package/dist/server/oauth/checks.d.ts.map +1 -1
- package/dist/server/oauth/checks.js +2 -1
- package/dist/server/oauth/checks.js.map +1 -1
- package/dist/server/oauth/convexAuth.d.ts.map +1 -1
- package/dist/server/oauth/convexAuth.js +3 -2
- package/dist/server/oauth/convexAuth.js.map +1 -1
- package/dist/server/provider_utils.d.ts +2 -0
- package/dist/server/provider_utils.d.ts.map +1 -1
- package/dist/server/types.d.ts +240 -5
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/server/utils.js +2 -1
- package/dist/server/utils.js.map +1 -1
- package/dist/server/version.d.ts +2 -0
- package/dist/server/version.d.ts.map +1 -0
- package/dist/server/version.js +3 -0
- package/dist/server/version.js.map +1 -0
- package/package.json +7 -2
- package/src/cli/index.ts +1 -1
- package/src/cli/utils.ts +248 -0
- package/src/client/index.ts +105 -15
- package/src/component/_generated/component.ts +61 -0
- package/src/component/index.ts +11 -2
- package/src/component/public.ts +142 -0
- package/src/component/schema.ts +52 -0
- package/src/providers/anonymous.ts +3 -0
- package/src/providers/credentials.ts +3 -0
- package/src/providers/email.ts +3 -0
- package/src/providers/passkey.ts +8 -1
- package/src/providers/password.ts +3 -0
- package/src/providers/phone.ts +3 -0
- package/src/providers/totp.ts +9 -0
- package/src/server/convex-auth.ts +385 -73
- package/src/server/email-templates.ts +77 -0
- package/src/server/errors.ts +269 -0
- package/src/server/implementation/apiKey.ts +186 -0
- package/src/server/implementation/index.ts +288 -28
- package/src/server/implementation/mutations/createAccountFromCredentials.ts +2 -1
- package/src/server/implementation/mutations/modifyAccount.ts +2 -3
- package/src/server/implementation/mutations/userOAuth.ts +2 -1
- package/src/server/implementation/mutations/verifierSignature.ts +2 -1
- package/src/server/implementation/passkey.ts +33 -35
- package/src/server/implementation/provider.ts +5 -8
- package/src/server/implementation/redirects.ts +2 -3
- package/src/server/implementation/refreshTokens.ts +2 -1
- package/src/server/implementation/signIn.ts +9 -18
- package/src/server/implementation/totp.ts +18 -21
- package/src/server/implementation/users.ts +4 -7
- package/src/server/index.ts +240 -37
- package/src/server/oauth/authorizationUrl.ts +2 -1
- package/src/server/oauth/callback.ts +5 -4
- package/src/server/oauth/checks.ts +3 -1
- package/src/server/oauth/convexAuth.ts +6 -3
- package/src/server/types.ts +254 -5
- package/src/server/utils.ts +3 -1
- package/src/server/version.ts +2 -0
- package/dist/server/portal.d.ts +0 -116
- package/dist/server/portal.d.ts.map +0 -1
- package/dist/server/portal.js +0 -294
- package/dist/server/portal.js.map +0 -1
- package/src/server/portal.ts +0 -375
|
@@ -6,11 +6,24 @@
|
|
|
6
6
|
* ```ts
|
|
7
7
|
* // convex/auth.ts
|
|
8
8
|
* import { Auth, Portal } from "@robelest/convex-auth/component";
|
|
9
|
-
* import
|
|
9
|
+
* import google from "@auth/core/providers/google";
|
|
10
10
|
* import { components } from "./_generated/api";
|
|
11
11
|
*
|
|
12
12
|
* export const auth = new Auth(components.auth, {
|
|
13
|
-
* providers: [
|
|
13
|
+
* providers: [google],
|
|
14
|
+
* email: {
|
|
15
|
+
* from: "My App <noreply@example.com>",
|
|
16
|
+
* send: async (_ctx, { from, to, subject, html }) => {
|
|
17
|
+
* await fetch("https://api.resend.com/emails", {
|
|
18
|
+
* method: "POST",
|
|
19
|
+
* headers: {
|
|
20
|
+
* Authorization: `Bearer ${process.env.AUTH_RESEND_KEY}`,
|
|
21
|
+
* "Content-Type": "application/json",
|
|
22
|
+
* },
|
|
23
|
+
* body: JSON.stringify({ from, to, subject, html }),
|
|
24
|
+
* });
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
14
27
|
* });
|
|
15
28
|
* export const { signIn, signOut, store } = auth;
|
|
16
29
|
* export const { portalQuery, portalMutation, portalInternal } = Portal(auth);
|
|
@@ -23,12 +36,17 @@ import type { ComponentApi as AuthComponentApi } from "../component/_generated/c
|
|
|
23
36
|
import { Auth as AuthFactory } from "./implementation/index.js";
|
|
24
37
|
import type { ConvexAuthConfig } from "./types.js";
|
|
25
38
|
/**
|
|
26
|
-
* Config for the
|
|
39
|
+
* Config for the Auth class. Extends the standard auth config
|
|
40
|
+
* minus `component` (which is passed as the first constructor argument).
|
|
27
41
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
42
|
+
* When `email` is configured, the library auto-registers:
|
|
43
|
+
* - A magic link provider (`id: "email"`) for user-facing sign-in
|
|
44
|
+
* - A portal provider (`id: "portal"`) for admin dashboard sign-in
|
|
45
|
+
*
|
|
46
|
+
* Portal functionality is always available — no configuration flag
|
|
47
|
+
* needed. The portal UI works when you export `portalQuery`,
|
|
48
|
+
* `portalMutation`, `portalInternal` from your `convex/auth.ts`
|
|
49
|
+
* and upload the portal static files via CLI.
|
|
32
50
|
*/
|
|
33
51
|
export type AuthClassConfig = Omit<ConvexAuthConfig, "component">;
|
|
34
52
|
/**
|
|
@@ -37,7 +55,11 @@ export type AuthClassConfig = Omit<ConvexAuthConfig, "component">;
|
|
|
37
55
|
*
|
|
38
56
|
* ```ts
|
|
39
57
|
* export const auth = new Auth(components.auth, {
|
|
40
|
-
* providers: [
|
|
58
|
+
* providers: [google, password],
|
|
59
|
+
* email: {
|
|
60
|
+
* from: "My App <noreply@example.com>",
|
|
61
|
+
* send: (ctx, params) => resend.sendEmail(ctx, params),
|
|
62
|
+
* },
|
|
41
63
|
* });
|
|
42
64
|
* export const { signIn, signOut, store } = auth;
|
|
43
65
|
* export const { portalQuery, portalMutation, portalInternal } = Portal(auth);
|
|
@@ -56,7 +78,7 @@ export declare class Auth {
|
|
|
56
78
|
readonly component: AuthComponentApi;
|
|
57
79
|
/** @internal */
|
|
58
80
|
readonly portalUrl: string;
|
|
59
|
-
/** User helpers: `.current(ctx)`, `.require(ctx)`, `.get(ctx, userId)`, `.viewer(ctx)` */
|
|
81
|
+
/** User helpers: `.current(ctx)`, `.require(ctx)`, `.get(ctx, userId)`, `.patch(ctx, userId, data)`, `.viewer(ctx)`, `.group.list(ctx, ...)`, `.group.get(ctx, ...)` */
|
|
60
82
|
get user(): {
|
|
61
83
|
current: (ctx: {
|
|
62
84
|
auth: import("convex/server").Auth;
|
|
@@ -68,6 +90,7 @@ export declare class Auth {
|
|
|
68
90
|
viewer: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery"> & {
|
|
69
91
|
auth: import("convex/server").Auth;
|
|
70
92
|
}) => Promise<any>;
|
|
93
|
+
patch: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, userId: string, data: Record<string, unknown>) => Promise<void>;
|
|
71
94
|
group: {
|
|
72
95
|
list: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery">, opts: {
|
|
73
96
|
userId: string;
|
|
@@ -78,7 +101,7 @@ export declare class Auth {
|
|
|
78
101
|
}) => Promise<any>;
|
|
79
102
|
};
|
|
80
103
|
};
|
|
81
|
-
/** Session helpers */
|
|
104
|
+
/** Session helpers: `.current(ctx)`, `.invalidate(ctx, { userId, except? })` */
|
|
82
105
|
get session(): {
|
|
83
106
|
current: (ctx: {
|
|
84
107
|
auth: import("convex/server").Auth;
|
|
@@ -88,7 +111,7 @@ export declare class Auth {
|
|
|
88
111
|
except?: import("convex/values").GenericId<"session">[];
|
|
89
112
|
}) => Promise<void>;
|
|
90
113
|
};
|
|
91
|
-
/** Provider helpers */
|
|
114
|
+
/** Provider helpers: `.signIn(ctx, provider, args)` */
|
|
92
115
|
get provider(): {
|
|
93
116
|
signIn: <DataModel extends import("convex/server").GenericDataModel>(ctx: import("convex/server").GenericActionCtx<DataModel>, provider: import("./types.js").AuthProviderConfig, args: {
|
|
94
117
|
accountId?: import("convex/values").GenericId<"account">;
|
|
@@ -98,7 +121,7 @@ export declare class Auth {
|
|
|
98
121
|
sessionId: import("convex/values").GenericId<"session">;
|
|
99
122
|
} | null>;
|
|
100
123
|
};
|
|
101
|
-
/** Account helpers */
|
|
124
|
+
/** Account helpers: `.create(ctx, args)`, `.get(ctx, args)`, `.updateCredentials(ctx, args)` */
|
|
102
125
|
get account(): {
|
|
103
126
|
create: <DataModel extends import("convex/server").GenericDataModel>(ctx: import("convex/server").GenericActionCtx<DataModel>, args: {
|
|
104
127
|
provider: string;
|
|
@@ -131,7 +154,7 @@ export declare class Auth {
|
|
|
131
154
|
};
|
|
132
155
|
}) => Promise<void>;
|
|
133
156
|
};
|
|
134
|
-
/** Group helpers */
|
|
157
|
+
/** Group helpers: `.create(ctx, ...)`, `.get(ctx, id)`, `.list(ctx, ...)`, `.update(ctx, ...)`, `.delete(ctx, id)`, `.member.*` */
|
|
135
158
|
get group(): {
|
|
136
159
|
create: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, data: {
|
|
137
160
|
name: string;
|
|
@@ -161,7 +184,7 @@ export declare class Auth {
|
|
|
161
184
|
update: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, memberId: string, data: Record<string, unknown>) => Promise<void>;
|
|
162
185
|
};
|
|
163
186
|
};
|
|
164
|
-
/** Invite helpers */
|
|
187
|
+
/** Invite helpers: `.create(ctx, ...)`, `.get(ctx, id)`, `.getByTokenHash(ctx, hash)`, `.list(ctx, ...)`, `.accept(ctx, ...)`, `.revoke(ctx, id)` */
|
|
165
188
|
get invite(): {
|
|
166
189
|
create: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, data: {
|
|
167
190
|
groupId?: string;
|
|
@@ -182,7 +205,7 @@ export declare class Auth {
|
|
|
182
205
|
accept: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, inviteId: string, acceptedByUserId?: string) => Promise<void>;
|
|
183
206
|
revoke: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, inviteId: string) => Promise<void>;
|
|
184
207
|
};
|
|
185
|
-
/** Passkey helpers */
|
|
208
|
+
/** Passkey helpers: `.list(ctx, { userId })`, `.rename(ctx, id, name)`, `.remove(ctx, id)` */
|
|
186
209
|
get passkey(): {
|
|
187
210
|
list: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery">, opts: {
|
|
188
211
|
userId: string;
|
|
@@ -190,13 +213,52 @@ export declare class Auth {
|
|
|
190
213
|
rename: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, passkeyId: string, name: string) => Promise<void>;
|
|
191
214
|
remove: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, passkeyId: string) => Promise<void>;
|
|
192
215
|
};
|
|
193
|
-
/** TOTP helpers */
|
|
216
|
+
/** TOTP helpers: `.list(ctx, { userId })`, `.remove(ctx, id)` */
|
|
194
217
|
get totp(): {
|
|
195
218
|
list: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery">, opts: {
|
|
196
219
|
userId: string;
|
|
197
220
|
}) => Promise<any>;
|
|
198
221
|
remove: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, totpId: string) => Promise<void>;
|
|
199
222
|
};
|
|
223
|
+
/** API key helpers: `.create(ctx, ...)`, `.verify(ctx, rawKey)`, `.list(ctx, ...)`, `.get(ctx, id)`, `.update(ctx, ...)`, `.revoke(ctx, id)`, `.remove(ctx, id)` */
|
|
224
|
+
get key(): {
|
|
225
|
+
create: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, opts: {
|
|
226
|
+
userId: string;
|
|
227
|
+
name: string;
|
|
228
|
+
scopes: import("./types.js").KeyScope[];
|
|
229
|
+
rateLimit?: {
|
|
230
|
+
maxRequests: number;
|
|
231
|
+
windowMs: number;
|
|
232
|
+
};
|
|
233
|
+
expiresAt?: number;
|
|
234
|
+
}) => Promise<{
|
|
235
|
+
keyId: string;
|
|
236
|
+
raw: string;
|
|
237
|
+
}>;
|
|
238
|
+
verify: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, rawKey: string) => Promise<{
|
|
239
|
+
userId: string;
|
|
240
|
+
keyId: string;
|
|
241
|
+
scopes: import("./types.js").ScopeChecker;
|
|
242
|
+
}>;
|
|
243
|
+
list: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery">, opts: {
|
|
244
|
+
userId: string;
|
|
245
|
+
}) => Promise<any>;
|
|
246
|
+
get: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery">, keyId: string) => Promise<any>;
|
|
247
|
+
update: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, keyId: string, data: {
|
|
248
|
+
name?: string;
|
|
249
|
+
scopes?: import("./types.js").KeyScope[];
|
|
250
|
+
rateLimit?: {
|
|
251
|
+
maxRequests: number;
|
|
252
|
+
windowMs: number;
|
|
253
|
+
};
|
|
254
|
+
}) => Promise<void>;
|
|
255
|
+
revoke: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, keyId: string) => Promise<void>;
|
|
256
|
+
remove: (ctx: Pick<import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, "runQuery" | "runMutation">, keyId: string) => Promise<void>;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* @param component - The auth component reference from `components.auth`.
|
|
260
|
+
* @param config - Auth configuration (providers, email transport, session, JWT, callbacks).
|
|
261
|
+
*/
|
|
200
262
|
constructor(component: AuthComponentApi, config: AuthClassConfig);
|
|
201
263
|
/**
|
|
202
264
|
* Register HTTP routes for OAuth, JWT well-known endpoints, and portal
|
|
@@ -211,6 +273,10 @@ export declare class Auth {
|
|
|
211
273
|
* auth.addHttpRoutes(http);
|
|
212
274
|
* export default http;
|
|
213
275
|
* ```
|
|
276
|
+
*
|
|
277
|
+
* @param http - The Convex HTTP router to register routes on.
|
|
278
|
+
* @param opts.pathPrefix - URL prefix for portal static files. Defaults to `"/auth"`.
|
|
279
|
+
* @param opts.spaFallback - Serve `index.html` for unmatched sub-paths. Defaults to `true`.
|
|
214
280
|
*/
|
|
215
281
|
addHttpRoutes(http: HttpRouter, opts?: {
|
|
216
282
|
pathPrefix?: string;
|
|
@@ -218,26 +284,120 @@ export declare class Auth {
|
|
|
218
284
|
}): void;
|
|
219
285
|
}
|
|
220
286
|
/**
|
|
221
|
-
* Create portal function definitions from
|
|
287
|
+
* Create portal function definitions from an `Auth` instance.
|
|
222
288
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* cannot trace through `instance.method()`.
|
|
289
|
+
* Standalone function (not a class method) because Convex's bundler
|
|
290
|
+
* can trace `export const { x } = fn(instance)` but not `instance.method()`.
|
|
226
291
|
*
|
|
227
292
|
* ```ts
|
|
228
293
|
* export const { portalQuery, portalMutation, portalInternal } = Portal(auth);
|
|
229
294
|
* ```
|
|
295
|
+
*
|
|
296
|
+
* @param auth - The `Auth` class instance from your `convex/auth.ts`.
|
|
297
|
+
* @returns `{ portalQuery, portalMutation, portalInternal }` — export all three.
|
|
230
298
|
*/
|
|
231
299
|
export declare function Portal(auth: Auth): {
|
|
232
300
|
portalQuery: import("convex/server").RegisteredQuery<"public", {
|
|
233
301
|
action: string;
|
|
234
302
|
userId?: string;
|
|
235
303
|
}, Promise<any>>;
|
|
236
|
-
portalMutation: import("convex/server").RegisteredMutation<"public",
|
|
237
|
-
action: string;
|
|
238
|
-
sessionId?: string;
|
|
239
|
-
tokenHash?: string;
|
|
240
|
-
}, Promise<void>>;
|
|
304
|
+
portalMutation: import("convex/server").RegisteredMutation<"public", any, Promise<any>>;
|
|
241
305
|
portalInternal: import("convex/server").RegisteredMutation<"internal", any, Promise<any>>;
|
|
242
306
|
};
|
|
307
|
+
/**
|
|
308
|
+
* Configuration for auth context enrichment.
|
|
309
|
+
*/
|
|
310
|
+
export type AuthCtxConfig = {
|
|
311
|
+
/**
|
|
312
|
+
* When `true`, unauthenticated requests set `ctx.auth.userId` and
|
|
313
|
+
* `ctx.auth.user` to `null` instead of throwing.
|
|
314
|
+
*
|
|
315
|
+
* @default false
|
|
316
|
+
*/
|
|
317
|
+
optional?: boolean;
|
|
318
|
+
/**
|
|
319
|
+
* Resolve additional context after authentication succeeds (e.g.
|
|
320
|
+
* group/role for multi-tenant apps). The returned object is spread
|
|
321
|
+
* into `ctx.auth`.
|
|
322
|
+
*/
|
|
323
|
+
resolve?: (ctx: any, user: any) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Create a `convex-helpers`–compatible customization object that
|
|
327
|
+
* enriches `ctx.auth` with the authenticated user's data.
|
|
328
|
+
*
|
|
329
|
+
* Standalone function (not a class method) because Convex's bundler
|
|
330
|
+
* can trace `export const x = fn(instance)` but not `instance.method()`.
|
|
331
|
+
*
|
|
332
|
+
* ### Basic usage (with `convex-helpers`)
|
|
333
|
+
*
|
|
334
|
+
* ```ts
|
|
335
|
+
* // convex/functions.ts
|
|
336
|
+
* import { customQuery, customMutation } from "convex-helpers/server/customFunctions";
|
|
337
|
+
* import { query as rawQuery, mutation as rawMutation } from "./_generated/server";
|
|
338
|
+
* import { AuthCtx } from "\@robelest/convex-auth/component";
|
|
339
|
+
* import { auth } from "./auth";
|
|
340
|
+
*
|
|
341
|
+
* const authCtx = AuthCtx(auth);
|
|
342
|
+
*
|
|
343
|
+
* export const query = customQuery(rawQuery, authCtx);
|
|
344
|
+
* export const mutation = customMutation(rawMutation, authCtx);
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* Then in any function file:
|
|
348
|
+
*
|
|
349
|
+
* ```ts
|
|
350
|
+
* // convex/messages.ts
|
|
351
|
+
* import { query, mutation } from "./functions";
|
|
352
|
+
*
|
|
353
|
+
* export const list = query({
|
|
354
|
+
* args: {},
|
|
355
|
+
* handler: async (ctx) => {
|
|
356
|
+
* // ctx.auth.userId and ctx.auth.user are already resolved
|
|
357
|
+
* return ctx.db.query("messages").collect();
|
|
358
|
+
* },
|
|
359
|
+
* });
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* ### Optional auth (public routes)
|
|
363
|
+
*
|
|
364
|
+
* ```ts
|
|
365
|
+
* export const publicQuery = customQuery(rawQuery, AuthCtx(auth, { optional: true }));
|
|
366
|
+
* // ctx.auth.userId is null when unauthenticated
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* ### Multi-tenant with group resolution
|
|
370
|
+
*
|
|
371
|
+
* ```ts
|
|
372
|
+
* const authCtx = AuthCtx(auth, {
|
|
373
|
+
* resolve: async (ctx, user) => {
|
|
374
|
+
* const groupId = user?.extend?.lastActiveGroup;
|
|
375
|
+
* const membership = await auth.user.group.get(ctx, {
|
|
376
|
+
* userId: user._id,
|
|
377
|
+
* groupId,
|
|
378
|
+
* });
|
|
379
|
+
* return { groupId, role: membership?.role ?? "member" };
|
|
380
|
+
* },
|
|
381
|
+
* });
|
|
382
|
+
* // ctx.auth.groupId and ctx.auth.role available in handlers
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* @param auth - The `Auth` class instance from your `convex/auth.ts`.
|
|
386
|
+
* @param config - Optional configuration for optional auth and group resolution.
|
|
387
|
+
* @returns A `{ args, input }` customization object compatible with
|
|
388
|
+
* `customQuery` / `customMutation` from `convex-helpers`.
|
|
389
|
+
*/
|
|
390
|
+
export declare function AuthCtx(auth: Auth, config?: AuthCtxConfig): {
|
|
391
|
+
args: {};
|
|
392
|
+
input: (ctx: any, _args: any, _extra?: any) => Promise<{
|
|
393
|
+
ctx: {
|
|
394
|
+
auth: {
|
|
395
|
+
getUserIdentity: any;
|
|
396
|
+
userId: any;
|
|
397
|
+
user: any;
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
args: {};
|
|
401
|
+
}>;
|
|
402
|
+
};
|
|
243
403
|
//# sourceMappingURL=convex-auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex-auth.d.ts","sourceRoot":"","sources":["../../src/server/convex-auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"convex-auth.d.ts","sourceRoot":"","sources":["../../src/server/convex-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;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