@robelest/convex-auth 0.0.2-preview.0 → 0.0.2-preview.2
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 +17 -15
- package/dist/client/index.d.ts +84 -30
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +259 -59
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/component.d.ts +46 -120
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/index.d.ts +2 -4
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/index.js +2 -4
- package/dist/component/index.js.map +1 -1
- package/dist/component/public.d.ts +233 -167
- package/dist/component/public.d.ts.map +1 -1
- package/dist/component/public.js +328 -155
- package/dist/component/public.js.map +1 -1
- package/dist/component/schema.d.ts +127 -12
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +136 -10
- package/dist/component/schema.js.map +1 -1
- package/dist/providers/{Anonymous.d.ts → anonymous.d.ts} +8 -8
- package/dist/providers/{Anonymous.d.ts.map → anonymous.d.ts.map} +1 -1
- package/dist/providers/{Anonymous.js → anonymous.js} +9 -10
- package/dist/providers/anonymous.js.map +1 -0
- package/dist/providers/{ConvexCredentials.d.ts → credentials.d.ts} +11 -11
- package/dist/providers/credentials.d.ts.map +1 -0
- package/dist/providers/{ConvexCredentials.js → credentials.js} +8 -8
- package/dist/providers/credentials.js.map +1 -0
- package/dist/providers/{Email.d.ts → email.d.ts} +6 -6
- package/dist/providers/email.d.ts.map +1 -0
- package/dist/providers/{Email.js → email.js} +6 -6
- package/dist/providers/email.js.map +1 -0
- package/dist/providers/{Password.d.ts → password.d.ts} +10 -10
- package/dist/providers/{Password.d.ts.map → password.d.ts.map} +1 -1
- package/dist/providers/{Password.js → password.js} +19 -20
- package/dist/providers/password.js.map +1 -0
- package/dist/providers/{Phone.d.ts → phone.d.ts} +3 -3
- package/dist/providers/{Phone.d.ts.map → phone.d.ts.map} +1 -1
- package/dist/providers/{Phone.js → phone.js} +3 -3
- package/dist/providers/{Phone.js.map → phone.js.map} +1 -1
- package/dist/server/implementation/db.d.ts +5 -2
- package/dist/server/implementation/db.d.ts.map +1 -1
- package/dist/server/implementation/db.js +2 -1
- package/dist/server/implementation/db.js.map +1 -1
- package/dist/server/implementation/index.d.ts +285 -180
- package/dist/server/implementation/index.d.ts.map +1 -1
- package/dist/server/implementation/index.js +280 -173
- 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 +8 -18
- package/dist/server/implementation/mutations/createAccountFromCredentials.js.map +1 -1
- package/dist/server/implementation/mutations/createVerificationCode.d.ts.map +1 -1
- package/dist/server/implementation/mutations/createVerificationCode.js +16 -44
- package/dist/server/implementation/mutations/createVerificationCode.js.map +1 -1
- package/dist/server/implementation/mutations/invalidateSessions.d.ts.map +1 -1
- package/dist/server/implementation/mutations/invalidateSessions.js +4 -8
- package/dist/server/implementation/mutations/invalidateSessions.js.map +1 -1
- package/dist/server/implementation/mutations/modifyAccount.d.ts.map +1 -1
- package/dist/server/implementation/mutations/modifyAccount.js +8 -19
- package/dist/server/implementation/mutations/modifyAccount.js.map +1 -1
- package/dist/server/implementation/mutations/refreshSession.d.ts.map +1 -1
- package/dist/server/implementation/mutations/refreshSession.js +9 -23
- package/dist/server/implementation/mutations/refreshSession.js.map +1 -1
- package/dist/server/implementation/mutations/retrieveAccountWithCredentials.d.ts.map +1 -1
- package/dist/server/implementation/mutations/retrieveAccountWithCredentials.js +6 -12
- package/dist/server/implementation/mutations/retrieveAccountWithCredentials.js.map +1 -1
- package/dist/server/implementation/mutations/signIn.d.ts.map +1 -1
- package/dist/server/implementation/mutations/signIn.js +2 -1
- package/dist/server/implementation/mutations/signIn.js.map +1 -1
- package/dist/server/implementation/mutations/signOut.d.ts.map +1 -1
- package/dist/server/implementation/mutations/signOut.js +5 -6
- package/dist/server/implementation/mutations/signOut.js.map +1 -1
- package/dist/server/implementation/mutations/storeRef.d.ts +8 -0
- package/dist/server/implementation/mutations/storeRef.d.ts.map +1 -0
- package/dist/server/implementation/mutations/storeRef.js +8 -0
- package/dist/server/implementation/mutations/storeRef.js.map +1 -0
- package/dist/server/implementation/mutations/userOAuth.d.ts.map +1 -1
- package/dist/server/implementation/mutations/userOAuth.js +16 -53
- package/dist/server/implementation/mutations/userOAuth.js.map +1 -1
- package/dist/server/implementation/mutations/verifier.d.ts.map +1 -1
- package/dist/server/implementation/mutations/verifier.js +4 -8
- package/dist/server/implementation/mutations/verifier.js.map +1 -1
- package/dist/server/implementation/mutations/verifierSignature.d.ts.map +1 -1
- package/dist/server/implementation/mutations/verifierSignature.js +6 -10
- package/dist/server/implementation/mutations/verifierSignature.js.map +1 -1
- package/dist/server/implementation/mutations/verifyCodeAndSignIn.d.ts.map +1 -1
- package/dist/server/implementation/mutations/verifyCodeAndSignIn.js +7 -16
- package/dist/server/implementation/mutations/verifyCodeAndSignIn.js.map +1 -1
- package/dist/server/implementation/provider.d.ts +2 -1
- package/dist/server/implementation/provider.d.ts.map +1 -1
- package/dist/server/implementation/provider.js.map +1 -1
- package/dist/server/implementation/rateLimit.d.ts.map +1 -1
- package/dist/server/implementation/rateLimit.js +13 -39
- package/dist/server/implementation/rateLimit.js.map +1 -1
- package/dist/server/implementation/refreshTokens.d.ts +1 -8
- package/dist/server/implementation/refreshTokens.d.ts.map +1 -1
- package/dist/server/implementation/refreshTokens.js +14 -58
- package/dist/server/implementation/refreshTokens.js.map +1 -1
- package/dist/server/implementation/sessions.d.ts +2 -20
- package/dist/server/implementation/sessions.d.ts.map +1 -1
- package/dist/server/implementation/sessions.js +8 -35
- package/dist/server/implementation/sessions.js.map +1 -1
- package/dist/server/implementation/types.d.ts +11 -267
- package/dist/server/implementation/types.d.ts.map +1 -1
- package/dist/server/implementation/types.js +1 -181
- package/dist/server/implementation/types.js.map +1 -1
- package/dist/server/implementation/users.d.ts.map +1 -1
- package/dist/server/implementation/users.js +19 -67
- package/dist/server/implementation/users.js.map +1 -1
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +255 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/provider_utils.d.ts +1 -1
- package/dist/server/provider_utils.d.ts.map +1 -1
- package/dist/server/provider_utils.js +2 -2
- package/dist/server/provider_utils.js.map +1 -1
- package/dist/server/types.d.ts +91 -52
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +3 -6
- package/src/cli/index.ts +20 -19
- package/src/client/index.ts +347 -110
- package/src/component/_generated/component.ts +55 -214
- package/src/component/index.ts +1 -11
- package/src/component/public.ts +366 -178
- package/src/component/schema.ts +150 -19
- package/src/providers/{Anonymous.ts → anonymous.ts} +10 -11
- package/src/providers/{ConvexCredentials.ts → credentials.ts} +11 -11
- package/src/providers/{Email.ts → email.ts} +5 -5
- package/src/providers/{Password.ts → password.ts} +22 -27
- package/src/providers/{Phone.ts → phone.ts} +2 -2
- package/src/server/implementation/db.ts +5 -2
- package/src/server/implementation/index.ts +368 -313
- package/src/server/implementation/mutations/createAccountFromCredentials.ts +11 -25
- package/src/server/implementation/mutations/createVerificationCode.ts +16 -47
- package/src/server/implementation/mutations/invalidateSessions.ts +4 -9
- package/src/server/implementation/mutations/modifyAccount.ts +8 -22
- package/src/server/implementation/mutations/refreshSession.ts +11 -24
- package/src/server/implementation/mutations/retrieveAccountWithCredentials.ts +9 -17
- package/src/server/implementation/mutations/signIn.ts +2 -1
- package/src/server/implementation/mutations/signOut.ts +5 -8
- package/src/server/implementation/mutations/storeRef.ts +7 -0
- package/src/server/implementation/mutations/userOAuth.ts +10 -50
- package/src/server/implementation/mutations/verifier.ts +4 -9
- package/src/server/implementation/mutations/verifierSignature.ts +6 -12
- package/src/server/implementation/mutations/verifyCodeAndSignIn.ts +7 -18
- package/src/server/implementation/provider.ts +2 -1
- package/src/server/implementation/rateLimit.ts +15 -41
- package/src/server/implementation/refreshTokens.ts +26 -76
- package/src/server/implementation/sessions.ts +8 -39
- package/src/server/implementation/types.ts +16 -191
- package/src/server/implementation/users.ts +19 -66
- package/src/server/index.ts +373 -0
- package/src/server/provider_utils.ts +2 -2
- package/src/server/types.ts +116 -51
- package/dist/providers/Anonymous.js.map +0 -1
- package/dist/providers/ConvexCredentials.d.ts.map +0 -1
- package/dist/providers/ConvexCredentials.js.map +0 -1
- package/dist/providers/Email.d.ts.map +0 -1
- package/dist/providers/Email.js.map +0 -1
- package/dist/providers/Password.js.map +0 -1
- package/providers/Anonymous/package.json +0 -6
- package/providers/ConvexCredentials/package.json +0 -6
- package/providers/Email/package.json +0 -6
- package/providers/Password/package.json +0 -6
- package/providers/Phone/package.json +0 -6
- package/server/package.json +0 -6
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Auth,
|
|
2
|
-
import { GenericId
|
|
3
|
-
import { FunctionReferenceFromExport
|
|
4
|
-
import { AuthProviderConfig, ConvexAuthConfig
|
|
1
|
+
import { Auth, GenericActionCtx, GenericDataModel, HttpRouter } from "convex/server";
|
|
2
|
+
import { GenericId } from "convex/values";
|
|
3
|
+
import { FunctionReferenceFromExport } from "../convex_types.js";
|
|
4
|
+
import { AuthProviderConfig, ConvexAuthConfig } from "../types.js";
|
|
5
5
|
import { Tokens } from "./types.js";
|
|
6
|
-
export {
|
|
7
|
-
export { getAuthSessionId } from "./sessions.js";
|
|
6
|
+
export { Doc, Tokens } from "./types.js";
|
|
8
7
|
/**
|
|
9
8
|
* The type of the signIn Convex Action returned from the auth() helper.
|
|
10
9
|
*
|
|
@@ -26,8 +25,10 @@ export type SignOutAction = FunctionReferenceFromExport<ReturnType<typeof Auth>[
|
|
|
26
25
|
*
|
|
27
26
|
* ```ts filename="convex/auth.ts"
|
|
28
27
|
* import { Auth } from "@robelest/convex-auth/component";
|
|
28
|
+
* import { components } from "./_generated/api";
|
|
29
29
|
*
|
|
30
30
|
* export const { auth, signIn, signOut, store } = Auth({
|
|
31
|
+
* component: components.auth,
|
|
31
32
|
* providers: [],
|
|
32
33
|
* });
|
|
33
34
|
* ```
|
|
@@ -41,44 +42,302 @@ export declare function Auth(config_: ConvexAuthConfig): {
|
|
|
41
42
|
*/
|
|
42
43
|
auth: {
|
|
43
44
|
user: {
|
|
45
|
+
/**
|
|
46
|
+
* Get the current user's ID from the auth context, or `null` if
|
|
47
|
+
* not signed in.
|
|
48
|
+
*/
|
|
44
49
|
current: (ctx: {
|
|
45
50
|
auth: Auth;
|
|
46
51
|
}) => Promise<GenericId<"user"> | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the current user's ID, or throw if not signed in.
|
|
54
|
+
* Use this when authentication is required.
|
|
55
|
+
*/
|
|
47
56
|
require: (ctx: {
|
|
48
57
|
auth: Auth;
|
|
49
58
|
}) => Promise<GenericId<"user">>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve a user document by their ID.
|
|
61
|
+
*/
|
|
50
62
|
get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, userId: string) => Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Get the currently signed-in user's document, or `null` if not
|
|
65
|
+
* signed in. Convenience method combining `current` + `get`.
|
|
66
|
+
*/
|
|
51
67
|
viewer: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery"> & {
|
|
52
68
|
auth: Auth;
|
|
53
69
|
}) => Promise<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Query a user's group memberships.
|
|
72
|
+
*/
|
|
73
|
+
group: {
|
|
74
|
+
/**
|
|
75
|
+
* List all groups a user belongs to. Returns member records which
|
|
76
|
+
* include the `groupId`, `role`, `status`, and `extend` for each.
|
|
77
|
+
*/
|
|
78
|
+
list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
|
|
79
|
+
userId: string;
|
|
80
|
+
}) => Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Look up a user's membership in a specific group. Returns the member
|
|
83
|
+
* record (with role, status, extend) or `null` if the user is not
|
|
84
|
+
* a member.
|
|
85
|
+
*/
|
|
86
|
+
get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
|
|
87
|
+
userId: string;
|
|
88
|
+
groupId: string;
|
|
89
|
+
}) => Promise<any>;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
session: {
|
|
93
|
+
/**
|
|
94
|
+
* Get the current session ID from the auth context, or `null` if
|
|
95
|
+
* not signed in.
|
|
96
|
+
*/
|
|
97
|
+
current: (ctx: {
|
|
98
|
+
auth: Auth;
|
|
99
|
+
}) => Promise<GenericId<"session"> | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Invalidate sessions for a user, optionally preserving specific sessions.
|
|
102
|
+
*/
|
|
103
|
+
invalidate: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
104
|
+
userId: GenericId<"user">;
|
|
105
|
+
except?: GenericId<"session">[];
|
|
106
|
+
}) => Promise<void>;
|
|
107
|
+
};
|
|
108
|
+
account: {
|
|
109
|
+
/**
|
|
110
|
+
* Create an account and user for a credentials provider.
|
|
111
|
+
*/
|
|
112
|
+
create: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
113
|
+
provider: string;
|
|
114
|
+
account: {
|
|
115
|
+
id: string;
|
|
116
|
+
secret?: string;
|
|
117
|
+
};
|
|
118
|
+
profile: Record<string, unknown>;
|
|
119
|
+
shouldLinkViaEmail?: boolean;
|
|
120
|
+
shouldLinkViaPhone?: boolean;
|
|
121
|
+
}) => Promise<{
|
|
122
|
+
account: import("./types.js").Doc<"account">;
|
|
123
|
+
user: import("./types.js").Doc<"user">;
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Retrieve an account and user for a credentials provider.
|
|
127
|
+
*/
|
|
128
|
+
get: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
129
|
+
provider: string;
|
|
130
|
+
account: {
|
|
131
|
+
id: string;
|
|
132
|
+
secret?: string;
|
|
133
|
+
};
|
|
134
|
+
}) => Promise<{
|
|
135
|
+
account: import("./types.js").Doc<"account">;
|
|
136
|
+
user: import("./types.js").Doc<"user">;
|
|
137
|
+
}>;
|
|
138
|
+
/**
|
|
139
|
+
* Update credentials for an existing account.
|
|
140
|
+
*/
|
|
141
|
+
updateCredentials: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
142
|
+
provider: string;
|
|
143
|
+
account: {
|
|
144
|
+
id: string;
|
|
145
|
+
secret: string;
|
|
146
|
+
};
|
|
147
|
+
}) => Promise<void>;
|
|
54
148
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
149
|
+
provider: {
|
|
150
|
+
/**
|
|
151
|
+
* Sign in via another provider, typically from a credentials flow.
|
|
152
|
+
*/
|
|
153
|
+
signIn: <DataModel extends GenericDataModel>(ctx: GenericActionCtx<DataModel>, provider: AuthProviderConfig, args: {
|
|
154
|
+
accountId?: GenericId<"account">;
|
|
155
|
+
params?: Record<string, unknown>;
|
|
156
|
+
}) => Promise<{
|
|
157
|
+
userId: GenericId<"user">;
|
|
158
|
+
sessionId: GenericId<"session">;
|
|
159
|
+
} | null>;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Hierarchical group management. Groups can nest arbitrarily deep
|
|
163
|
+
* via `parentGroupId`. A root group has no parent.
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* const groupId = await auth.group.create(ctx, { name: "Acme Corp" });
|
|
167
|
+
* const subGroupId = await auth.group.create(ctx, {
|
|
168
|
+
* name: "Engineering",
|
|
169
|
+
* parentGroupId: groupId,
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
group: {
|
|
174
|
+
/**
|
|
175
|
+
* Create a new group. Omit `parentGroupId` for a root-level group,
|
|
176
|
+
* or provide it to create a nested group.
|
|
177
|
+
*
|
|
178
|
+
* @returns The ID of the newly created group.
|
|
179
|
+
*/
|
|
180
|
+
create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
|
|
181
|
+
name: string;
|
|
182
|
+
slug?: string;
|
|
183
|
+
parentGroupId?: string;
|
|
184
|
+
extend?: Record<string, unknown>;
|
|
185
|
+
}) => Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Retrieve a group by its ID. Returns `null` if not found.
|
|
188
|
+
*/
|
|
189
|
+
get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, groupId: string) => Promise<any>;
|
|
190
|
+
/**
|
|
191
|
+
* List groups. When `parentGroupId` is provided, returns children of
|
|
192
|
+
* that group. When omitted, returns root-level groups (no parent).
|
|
193
|
+
*/
|
|
194
|
+
list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
|
|
195
|
+
parentGroupId?: string;
|
|
196
|
+
}) => Promise<any>;
|
|
197
|
+
/**
|
|
198
|
+
* Update a group's fields (name, slug, extend, parentGroupId).
|
|
199
|
+
*/
|
|
200
|
+
update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, groupId: string, data: Record<string, unknown>) => Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Delete a group and cascade to all descendants. Deletes child groups
|
|
203
|
+
* (recursively), all members, and all invites for this group and its
|
|
204
|
+
* descendants.
|
|
205
|
+
*/
|
|
206
|
+
delete: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, groupId: string) => Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Manage group membership. A member links a user to a group with an
|
|
209
|
+
* application-defined role string (e.g. "owner", "admin", "member").
|
|
210
|
+
*
|
|
211
|
+
* The auth component stores roles but does not enforce access control.
|
|
212
|
+
* Your application defines what each role means.
|
|
213
|
+
*/
|
|
61
214
|
member: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Add a user as a member of a group.
|
|
217
|
+
*
|
|
218
|
+
* @param data.groupId - The group to add the member to.
|
|
219
|
+
* @param data.userId - The user to add.
|
|
220
|
+
* @param data.role - Application-defined role (e.g. "owner", "admin", "member").
|
|
221
|
+
* @param data.status - Optional membership status (e.g. "active", "suspended").
|
|
222
|
+
* @param data.extend - Optional arbitrary JSON extension data.
|
|
223
|
+
* @throws ConvexError with code `DUPLICATE_MEMBERSHIP` if the user is
|
|
224
|
+
* already a member of the target group.
|
|
225
|
+
* @returns The ID of the new member record.
|
|
226
|
+
*/
|
|
227
|
+
add: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
|
|
228
|
+
groupId: string;
|
|
229
|
+
userId: string;
|
|
230
|
+
role?: string;
|
|
231
|
+
status?: string;
|
|
232
|
+
extend?: Record<string, unknown>;
|
|
233
|
+
}) => Promise<string>;
|
|
234
|
+
/**
|
|
235
|
+
* Retrieve a member record by its ID. Returns `null` if not found.
|
|
236
|
+
*/
|
|
237
|
+
get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, memberId: string) => Promise<any>;
|
|
238
|
+
/**
|
|
239
|
+
* List all members of a group.
|
|
240
|
+
*/
|
|
241
|
+
list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts: {
|
|
242
|
+
groupId: string;
|
|
67
243
|
}) => Promise<any>;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Remove a member from a group by deleting the member record.
|
|
246
|
+
*/
|
|
247
|
+
remove: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, memberId: string) => Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* Update a member's fields (role, status, extend).
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* await auth.group.member.update(ctx, memberId, { role: "admin" });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
update: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, memberId: string, data: Record<string, unknown>) => Promise<void>;
|
|
72
256
|
};
|
|
73
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Manage platform-level invitations.
|
|
260
|
+
*
|
|
261
|
+
* Invites can optionally target a group by setting `groupId`, but they do
|
|
262
|
+
* not require groups and can be used in apps with user-only collaboration.
|
|
263
|
+
*/
|
|
74
264
|
invite: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Create a new invitation.
|
|
267
|
+
*
|
|
268
|
+
* @param data.groupId - Optional group to invite the user into.
|
|
269
|
+
* @param data.invitedByUserId - The user sending the invitation.
|
|
270
|
+
* @param data.email - The email address of the invitee.
|
|
271
|
+
* @param data.tokenHash - Hashed token for secure acceptance.
|
|
272
|
+
* @param data.role - Optional role to assign on acceptance.
|
|
273
|
+
* @param data.status - Initial status (typically "pending").
|
|
274
|
+
* @param data.expiresTime - Timestamp when the invite expires.
|
|
275
|
+
* @param data.extend - Optional arbitrary JSON extension data.
|
|
276
|
+
* @throws ConvexError with code `DUPLICATE_INVITE` if a pending invite
|
|
277
|
+
* already exists for this email and scope.
|
|
278
|
+
* @returns The ID of the new invite record.
|
|
279
|
+
*/
|
|
280
|
+
create: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, data: {
|
|
281
|
+
groupId?: string;
|
|
282
|
+
invitedByUserId: string;
|
|
283
|
+
email: string;
|
|
284
|
+
tokenHash: string;
|
|
285
|
+
role?: string;
|
|
286
|
+
status: "pending" | "accepted" | "revoked" | "expired";
|
|
287
|
+
expiresTime: number;
|
|
288
|
+
extend?: Record<string, unknown>;
|
|
289
|
+
}) => Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Retrieve an invite by its ID. Returns `null` if not found.
|
|
292
|
+
*/
|
|
293
|
+
get: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, inviteId: string) => Promise<any>;
|
|
294
|
+
/**
|
|
295
|
+
* List invites, optionally filtered by group and/or status.
|
|
296
|
+
*/
|
|
297
|
+
list: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery">, opts?: {
|
|
298
|
+
groupId?: string;
|
|
299
|
+
status?: "pending" | "accepted" | "revoked" | "expired";
|
|
80
300
|
}) => Promise<any>;
|
|
301
|
+
/**
|
|
302
|
+
* Accept an invitation. Marks the invite as "accepted" and records
|
|
303
|
+
* the timestamp. If the invite has a group, the caller is responsible
|
|
304
|
+
* for creating the member record via `auth.group.member.add` in the
|
|
305
|
+
* same Convex mutation for transactional safety.
|
|
306
|
+
*
|
|
307
|
+
* @throws ConvexError with code `INVITE_NOT_FOUND` when the invite does
|
|
308
|
+
* not exist.
|
|
309
|
+
* @throws ConvexError with code `INVITE_NOT_PENDING` when the invite is
|
|
310
|
+
* not in `pending` status.
|
|
311
|
+
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* export const acceptInvite = mutation({
|
|
314
|
+
* args: { inviteId: v.string() },
|
|
315
|
+
* handler: async (ctx, { inviteId }) => {
|
|
316
|
+
* const userId = await auth.user.require(ctx);
|
|
317
|
+
* const invite = await auth.invite.get(ctx, inviteId);
|
|
318
|
+
* if (!invite) throw new Error("Invite not found");
|
|
319
|
+
*
|
|
320
|
+
* await auth.invite.accept(ctx, inviteId);
|
|
321
|
+
* if (invite.groupId) {
|
|
322
|
+
* await auth.group.member.add(ctx, {
|
|
323
|
+
* groupId: invite.groupId,
|
|
324
|
+
* userId,
|
|
325
|
+
* role: invite.role,
|
|
326
|
+
* });
|
|
327
|
+
* }
|
|
328
|
+
* },
|
|
329
|
+
* });
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
81
332
|
accept: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, inviteId: string) => Promise<void>;
|
|
333
|
+
/**
|
|
334
|
+
* Revoke a pending invitation.
|
|
335
|
+
*
|
|
336
|
+
* @throws ConvexError with code `INVITE_NOT_FOUND` when the invite does
|
|
337
|
+
* not exist.
|
|
338
|
+
* @throws ConvexError with code `INVITE_NOT_PENDING` when the invite is
|
|
339
|
+
* not in `pending` status.
|
|
340
|
+
*/
|
|
82
341
|
revoke: (ctx: Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "runMutation">, inviteId: string) => Promise<void>;
|
|
83
342
|
};
|
|
84
343
|
/**
|
|
@@ -213,158 +472,4 @@ export declare function Auth(config_: ConvexAuthConfig): {
|
|
|
213
472
|
user: import("./types.js").Doc<"user">;
|
|
214
473
|
} | null>>;
|
|
215
474
|
};
|
|
216
|
-
/**
|
|
217
|
-
* Return the currently signed-in user's ID.
|
|
218
|
-
*
|
|
219
|
-
* ```ts filename="convex/myFunctions.tsx"
|
|
220
|
-
* import { mutation } from "./_generated/server";
|
|
221
|
-
* import { getAuthUserId } from "@robelest/convex-auth/component";
|
|
222
|
-
*
|
|
223
|
-
* export const doSomething = mutation({
|
|
224
|
-
* args: {/* ... *\/},
|
|
225
|
-
* handler: async (ctx, args) => {
|
|
226
|
-
* const userId = await getAuthUserId(ctx);
|
|
227
|
-
* if (userId === null) {
|
|
228
|
-
* throw new Error("Client is not authenticated!")
|
|
229
|
-
* }
|
|
230
|
-
* const user = await ctx.db.get(userId);
|
|
231
|
-
* // ...
|
|
232
|
-
* },
|
|
233
|
-
* });
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* @param ctx query, mutation or action `ctx`
|
|
237
|
-
* @returns the user ID or `null` if the client isn't authenticated
|
|
238
|
-
*/
|
|
239
|
-
export declare function getAuthUserId(ctx: {
|
|
240
|
-
auth: Auth;
|
|
241
|
-
}): Promise<GenericId<"user"> | null>;
|
|
242
|
-
/**
|
|
243
|
-
* Use this function from a
|
|
244
|
-
* [`ConvexCredentials`](https://labs.convex.dev/auth/api_reference/providers/ConvexCredentials)
|
|
245
|
-
* provider to create an account and a user with a unique account "id" (OAuth
|
|
246
|
-
* provider ID, email address, phone number, username etc.).
|
|
247
|
-
*
|
|
248
|
-
* @returns user ID if it successfully creates the account
|
|
249
|
-
* or throws an error.
|
|
250
|
-
*/
|
|
251
|
-
export declare function createAccount<DataModel extends GenericDataModel = GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
252
|
-
/**
|
|
253
|
-
* The provider ID (like "password"), used to disambiguate accounts.
|
|
254
|
-
*
|
|
255
|
-
* It is also used to configure account secret hashing via the provider's
|
|
256
|
-
* `crypto` option.
|
|
257
|
-
*/
|
|
258
|
-
provider: string;
|
|
259
|
-
account: {
|
|
260
|
-
/**
|
|
261
|
-
* The unique external ID for the account, for example email address.
|
|
262
|
-
*/
|
|
263
|
-
id: string;
|
|
264
|
-
/**
|
|
265
|
-
* The secret credential to store for this account, if given.
|
|
266
|
-
*/
|
|
267
|
-
secret?: string;
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* The profile data to store for the user.
|
|
271
|
-
* These must fit the `users` table schema.
|
|
272
|
-
*/
|
|
273
|
-
profile: WithoutSystemFields<DocumentByName<DataModel, "user">>;
|
|
274
|
-
/**
|
|
275
|
-
* If `true`, the account will be linked to an existing user
|
|
276
|
-
* with the same verified email address.
|
|
277
|
-
* This is only safe if the returned account's email is verified
|
|
278
|
-
* before the user is allowed to sign in with it.
|
|
279
|
-
*/
|
|
280
|
-
shouldLinkViaEmail?: boolean;
|
|
281
|
-
/**
|
|
282
|
-
* If `true`, the account will be linked to an existing user
|
|
283
|
-
* with the same verified phone number.
|
|
284
|
-
* This is only safe if the returned account's phone is verified
|
|
285
|
-
* before the user is allowed to sign in with it.
|
|
286
|
-
*/
|
|
287
|
-
shouldLinkViaPhone?: boolean;
|
|
288
|
-
}): Promise<{
|
|
289
|
-
account: GenericDoc<DataModel, "account">;
|
|
290
|
-
user: GenericDoc<DataModel, "user">;
|
|
291
|
-
}>;
|
|
292
|
-
/**
|
|
293
|
-
* Use this function from a
|
|
294
|
-
* [`ConvexCredentials`](https://labs.convex.dev/auth/api_reference/providers/ConvexCredentials)
|
|
295
|
-
* provider to retrieve a user given the account provider ID and
|
|
296
|
-
* the provider-specific account ID.
|
|
297
|
-
*
|
|
298
|
-
* @returns the retrieved user document, or `null` if there is no account
|
|
299
|
-
* for given account ID or throws if the provided
|
|
300
|
-
* secret does not match.
|
|
301
|
-
*/
|
|
302
|
-
export declare function retrieveAccount<DataModel extends GenericDataModel = GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
303
|
-
/**
|
|
304
|
-
* The provider ID (like "password"), used to disambiguate accounts.
|
|
305
|
-
*
|
|
306
|
-
* It is also used to configure account secret hashing via the provider's
|
|
307
|
-
* `crypto` option.
|
|
308
|
-
*/
|
|
309
|
-
provider: string;
|
|
310
|
-
account: {
|
|
311
|
-
/**
|
|
312
|
-
* The unique external ID for the account, for example email address.
|
|
313
|
-
*/
|
|
314
|
-
id: string;
|
|
315
|
-
/**
|
|
316
|
-
* The secret that should match the stored credential, if given.
|
|
317
|
-
*/
|
|
318
|
-
secret?: string;
|
|
319
|
-
};
|
|
320
|
-
}): Promise<{
|
|
321
|
-
account: GenericDoc<DataModel, "account">;
|
|
322
|
-
user: GenericDoc<DataModel, "user">;
|
|
323
|
-
}>;
|
|
324
|
-
/**
|
|
325
|
-
* Use this function to modify the account credentials
|
|
326
|
-
* from a [`ConvexCredentials`](https://labs.convex.dev/auth/api_reference/providers/ConvexCredentials)
|
|
327
|
-
* provider.
|
|
328
|
-
*/
|
|
329
|
-
export declare function modifyAccountCredentials<DataModel extends GenericDataModel = GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
330
|
-
/**
|
|
331
|
-
* The provider ID (like "password"), used to disambiguate accounts.
|
|
332
|
-
*
|
|
333
|
-
* It is also used to configure account secret hashing via the `crypto` option.
|
|
334
|
-
*/
|
|
335
|
-
provider: string;
|
|
336
|
-
account: {
|
|
337
|
-
/**
|
|
338
|
-
* The unique external ID for the account, for example email address.
|
|
339
|
-
*/
|
|
340
|
-
id: string;
|
|
341
|
-
/**
|
|
342
|
-
* The new secret credential to store for this account.
|
|
343
|
-
*/
|
|
344
|
-
secret: string;
|
|
345
|
-
};
|
|
346
|
-
}): Promise<void>;
|
|
347
|
-
/**
|
|
348
|
-
* Use this function to invalidate existing sessions.
|
|
349
|
-
*/
|
|
350
|
-
export declare function invalidateSessions<DataModel extends GenericDataModel = GenericDataModel>(ctx: GenericActionCtx<DataModel>, args: {
|
|
351
|
-
userId: GenericId<"user">;
|
|
352
|
-
except?: GenericId<"session">[];
|
|
353
|
-
}): Promise<void>;
|
|
354
|
-
/**
|
|
355
|
-
* Use this function from a
|
|
356
|
-
* [`ConvexCredentials`](https://labs.convex.dev/auth/api_reference/providers/ConvexCredentials)
|
|
357
|
-
* provider to sign in the user via another provider (usually
|
|
358
|
-
* for email verification on sign up or password reset).
|
|
359
|
-
*
|
|
360
|
-
* Returns the user ID if the sign can proceed,
|
|
361
|
-
* or `null`.
|
|
362
|
-
*/
|
|
363
|
-
export declare function signInViaProvider<DataModel extends GenericDataModel = GenericDataModel>(ctx: GenericActionCtxWithAuthConfig<DataModel>, provider: AuthProviderConfig, args: {
|
|
364
|
-
accountId?: GenericId<"account">;
|
|
365
|
-
params?: Record<string, Value | undefined>;
|
|
366
|
-
}): Promise<{
|
|
367
|
-
userId: GenericId<"user">;
|
|
368
|
-
sessionId: GenericId<"session">;
|
|
369
|
-
} | null>;
|
|
370
475
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/implementation/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/implementation/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,UA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