@robelest/convex-auth 0.0.2-preview.1 → 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/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/index.d.ts +2 -2
- package/dist/component/index.d.ts.map +1 -1
- package/dist/component/index.js +2 -2
- package/dist/component/index.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/index.d.ts +73 -159
- package/dist/server/implementation/index.d.ts.map +1 -1
- package/dist/server/implementation/index.js +74 -100
- package/dist/server/implementation/index.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 +2 -20
- package/dist/server/implementation/sessions.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.map +1 -1
- package/dist/server/types.d.ts +70 -9
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +3 -6
- package/src/client/index.ts +347 -110
- package/src/component/index.ts +1 -8
- 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/index.ts +119 -231
- package/src/server/implementation/sessions.ts +2 -20
- package/src/server/index.ts +373 -0
- package/src/server/types.ts +95 -8
- 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,22 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configure {@link
|
|
2
|
+
* Configure {@link anonymous} provider given an {@link AnonymousConfig}.
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
|
-
* import
|
|
6
|
-
* import {
|
|
5
|
+
* import anonymous from "@robelest/convex-auth/providers/anonymous";
|
|
6
|
+
* import { Auth } from "@robelest/convex-auth/component";
|
|
7
7
|
*
|
|
8
|
-
* export const { auth, signIn, signOut, store } =
|
|
9
|
-
* providers: [
|
|
8
|
+
* export const { auth, signIn, signOut, store } = Auth({
|
|
9
|
+
* providers: [anonymous],
|
|
10
10
|
* });
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import
|
|
16
|
+
import credentials from "@robelest/convex-auth/providers/credentials";
|
|
17
17
|
import {
|
|
18
18
|
GenericActionCtxWithAuthConfig,
|
|
19
|
-
createAccount,
|
|
20
19
|
} from "@robelest/convex-auth/component";
|
|
21
20
|
import {
|
|
22
21
|
DocumentByName,
|
|
@@ -26,12 +25,12 @@ import {
|
|
|
26
25
|
import { Value } from "convex/values";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
* The available options to an {@link
|
|
28
|
+
* The available options to an {@link anonymous} provider for Convex Auth.
|
|
30
29
|
*/
|
|
31
30
|
export interface AnonymousConfig<DataModel extends GenericDataModel> {
|
|
32
31
|
/**
|
|
33
32
|
* Uniquely identifies the provider, allowing to use
|
|
34
|
-
* multiple different {@link
|
|
33
|
+
* multiple different {@link anonymous} providers.
|
|
35
34
|
*/
|
|
36
35
|
id?: string;
|
|
37
36
|
/**
|
|
@@ -62,11 +61,11 @@ export default function anonymous<DataModel extends GenericDataModel>(
|
|
|
62
61
|
config: AnonymousConfig<DataModel> = {},
|
|
63
62
|
) {
|
|
64
63
|
const provider = config.id ?? "anonymous";
|
|
65
|
-
return
|
|
64
|
+
return credentials<DataModel>({
|
|
66
65
|
id: "anonymous",
|
|
67
66
|
authorize: async (params, ctx) => {
|
|
68
67
|
const profile = config.profile?.(params, ctx) ?? { isAnonymous: true };
|
|
69
|
-
const { user } = await
|
|
68
|
+
const { user } = await ctx.auth.account.create(ctx, {
|
|
70
69
|
provider,
|
|
71
70
|
account: { id: crypto.randomUUID() },
|
|
72
71
|
profile: profile as any,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configure {@link
|
|
2
|
+
* Configure {@link credentials} provider given a {@link CredentialsUserConfig}.
|
|
3
3
|
*
|
|
4
4
|
* This is for a very custom authentication implementation, often you can
|
|
5
|
-
* use the [`
|
|
5
|
+
* use the [`password`](https://labs.convex.dev/auth/api_reference/providers/password) provider instead.
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
|
-
* import
|
|
9
|
-
* import {
|
|
8
|
+
* import credentials from "@robelest/convex-auth/providers/credentials";
|
|
9
|
+
* import { Auth } from "@robelest/convex-auth/component";
|
|
10
10
|
*
|
|
11
|
-
* export const { auth, signIn, signOut, store } =
|
|
11
|
+
* export const { auth, signIn, signOut, store } = Auth({
|
|
12
12
|
* providers: [
|
|
13
|
-
*
|
|
13
|
+
* credentials({
|
|
14
14
|
* authorize: async (credentials, ctx) => {
|
|
15
15
|
* // Your custom logic here...
|
|
16
16
|
* },
|
|
@@ -31,14 +31,14 @@ import { GenericDataModel } from "convex/server";
|
|
|
31
31
|
import { GenericId, Value } from "convex/values";
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* The available options to a {@link
|
|
34
|
+
* The available options to a {@link credentials} provider for Convex Auth.
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface CredentialsUserConfig<
|
|
37
37
|
DataModel extends GenericDataModel = GenericDataModel,
|
|
38
38
|
> {
|
|
39
39
|
/**
|
|
40
40
|
* Uniquely identifies the provider, allowing to use
|
|
41
|
-
* multiple different {@link
|
|
41
|
+
* multiple different {@link credentials} providers.
|
|
42
42
|
*/
|
|
43
43
|
id?: string;
|
|
44
44
|
/**
|
|
@@ -95,8 +95,8 @@ export interface ConvexCredentialsUserConfig<
|
|
|
95
95
|
* The Credentials provider allows you to handle signing in with arbitrary credentials,
|
|
96
96
|
* such as a username and password, domain, or two factor authentication or hardware device (e.g. YubiKey U2F / FIDO).
|
|
97
97
|
*/
|
|
98
|
-
export default function
|
|
99
|
-
config:
|
|
98
|
+
export default function credentials<DataModel extends GenericDataModel>(
|
|
99
|
+
config: CredentialsUserConfig<DataModel>,
|
|
100
100
|
): ConvexCredentialsConfig {
|
|
101
101
|
return {
|
|
102
102
|
id: "credentials",
|
|
@@ -19,19 +19,19 @@ import { EmailConfig, EmailUserConfig } from "../server/types.js";
|
|
|
19
19
|
* you can override the `authorize` method to skip the check:
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
|
-
* import
|
|
23
|
-
* import {
|
|
22
|
+
* import email from "@robelest/convex-auth/providers/email";
|
|
23
|
+
* import { Auth } from "@robelest/convex-auth/component";
|
|
24
24
|
*
|
|
25
|
-
* export const { auth, signIn, signOut, store } =
|
|
25
|
+
* export const { auth, signIn, signOut, store } = Auth({
|
|
26
26
|
* providers: [
|
|
27
|
-
*
|
|
27
|
+
* email({ authorize: undefined }),
|
|
28
28
|
* ],
|
|
29
29
|
* });
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
32
|
* Make sure the token has high enough entropy to be secure.
|
|
33
33
|
*/
|
|
34
|
-
export function
|
|
34
|
+
export default function email<DataModel extends GenericDataModel>(
|
|
35
35
|
config: EmailUserConfig<DataModel> &
|
|
36
36
|
Pick<EmailConfig, "sendVerificationRequest">,
|
|
37
37
|
): EmailConfig<DataModel> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configure {@link
|
|
2
|
+
* Configure {@link password} provider given a {@link PasswordConfig}.
|
|
3
3
|
*
|
|
4
|
-
* The `
|
|
4
|
+
* The `password` provider supports the following flows, determined
|
|
5
5
|
* by the `flow` parameter:
|
|
6
6
|
*
|
|
7
7
|
* - `"signUp"`: Create a new account with a password.
|
|
@@ -12,29 +12,24 @@
|
|
|
12
12
|
* included in params, verify an OTP.
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
|
-
* import
|
|
16
|
-
* import {
|
|
15
|
+
* import password from "@robelest/convex-auth/providers/password";
|
|
16
|
+
* import { Auth } from "@robelest/convex-auth/component";
|
|
17
17
|
*
|
|
18
|
-
* export const { auth, signIn, signOut, store } =
|
|
19
|
-
* providers: [
|
|
18
|
+
* export const { auth, signIn, signOut, store } = Auth({
|
|
19
|
+
* providers: [password],
|
|
20
20
|
* });
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
} from "@robelest/convex-auth/providers/
|
|
26
|
+
import credentials, {
|
|
27
|
+
CredentialsUserConfig,
|
|
28
|
+
} from "@robelest/convex-auth/providers/credentials";
|
|
29
29
|
import {
|
|
30
30
|
EmailConfig,
|
|
31
31
|
GenericActionCtxWithAuthConfig,
|
|
32
32
|
GenericDoc,
|
|
33
|
-
createAccount,
|
|
34
|
-
invalidateSessions,
|
|
35
|
-
modifyAccountCredentials,
|
|
36
|
-
retrieveAccount,
|
|
37
|
-
signInViaProvider,
|
|
38
33
|
} from "@robelest/convex-auth/component";
|
|
39
34
|
import {
|
|
40
35
|
DocumentByName,
|
|
@@ -45,7 +40,7 @@ import { Value } from "convex/values";
|
|
|
45
40
|
import { Scrypt } from "lucia";
|
|
46
41
|
|
|
47
42
|
/**
|
|
48
|
-
* The available options to a {@link
|
|
43
|
+
* The available options to a {@link password} provider for Convex Auth.
|
|
49
44
|
*/
|
|
50
45
|
export interface PasswordConfig<DataModel extends GenericDataModel> {
|
|
51
46
|
/**
|
|
@@ -89,7 +84,7 @@ export interface PasswordConfig<DataModel extends GenericDataModel> {
|
|
|
89
84
|
* Provide hashing and verification functions if you want to control
|
|
90
85
|
* how passwords are hashed.
|
|
91
86
|
*/
|
|
92
|
-
crypto?:
|
|
87
|
+
crypto?: CredentialsUserConfig["crypto"];
|
|
93
88
|
/**
|
|
94
89
|
* An Auth.js email provider used to require verification
|
|
95
90
|
* before password reset.
|
|
@@ -115,7 +110,7 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
115
110
|
config: PasswordConfig<DataModel> = {},
|
|
116
111
|
) {
|
|
117
112
|
const provider = config.id ?? "password";
|
|
118
|
-
return
|
|
113
|
+
return credentials<DataModel>({
|
|
119
114
|
id: "password",
|
|
120
115
|
authorize: async (params, ctx) => {
|
|
121
116
|
const flow = params.flow as string;
|
|
@@ -141,7 +136,7 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
141
136
|
if (secret === undefined) {
|
|
142
137
|
throw new Error("Missing `password` param for `signUp` flow");
|
|
143
138
|
}
|
|
144
|
-
const created = await
|
|
139
|
+
const created = await ctx.auth.account.create(ctx, {
|
|
145
140
|
provider,
|
|
146
141
|
account: { id: email, secret },
|
|
147
142
|
profile: profile as any,
|
|
@@ -153,7 +148,7 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
153
148
|
if (secret === undefined) {
|
|
154
149
|
throw new Error("Missing `password` param for `signIn` flow");
|
|
155
150
|
}
|
|
156
|
-
const retrieved = await
|
|
151
|
+
const retrieved = await ctx.auth.account.get(ctx, {
|
|
157
152
|
provider,
|
|
158
153
|
account: { id: email, secret },
|
|
159
154
|
});
|
|
@@ -166,11 +161,11 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
166
161
|
if (!config.reset) {
|
|
167
162
|
throw new Error(`Password reset is not enabled for ${provider}`);
|
|
168
163
|
}
|
|
169
|
-
const { account } = await
|
|
164
|
+
const { account } = await ctx.auth.account.get(ctx, {
|
|
170
165
|
provider,
|
|
171
166
|
account: { id: email },
|
|
172
167
|
});
|
|
173
|
-
return await
|
|
168
|
+
return await ctx.auth.provider.signIn(ctx, config.reset, {
|
|
174
169
|
accountId: account._id,
|
|
175
170
|
params,
|
|
176
171
|
});
|
|
@@ -183,17 +178,17 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
183
178
|
"Missing `newPassword` param for `reset-verification` flow",
|
|
184
179
|
);
|
|
185
180
|
}
|
|
186
|
-
const result = await
|
|
181
|
+
const result = await ctx.auth.provider.signIn(ctx, config.reset, { params });
|
|
187
182
|
if (result === null) {
|
|
188
183
|
throw new Error("Invalid code");
|
|
189
184
|
}
|
|
190
185
|
const { userId, sessionId } = result;
|
|
191
186
|
const secret = params.newPassword as string;
|
|
192
|
-
await
|
|
187
|
+
await ctx.auth.account.updateCredentials(ctx, {
|
|
193
188
|
provider,
|
|
194
189
|
account: { id: email, secret },
|
|
195
190
|
});
|
|
196
|
-
await
|
|
191
|
+
await ctx.auth.session.invalidate(ctx, { userId, except: [sessionId] });
|
|
197
192
|
return { userId, sessionId };
|
|
198
193
|
// END
|
|
199
194
|
// START: Optional, email verification during sign in
|
|
@@ -201,11 +196,11 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
201
196
|
if (!config.verify) {
|
|
202
197
|
throw new Error(`Email verification is not enabled for ${provider}`);
|
|
203
198
|
}
|
|
204
|
-
const { account } = await
|
|
199
|
+
const { account } = await ctx.auth.account.get(ctx, {
|
|
205
200
|
provider,
|
|
206
201
|
account: { id: email },
|
|
207
202
|
});
|
|
208
|
-
return await
|
|
203
|
+
return await ctx.auth.provider.signIn(ctx, config.verify, {
|
|
209
204
|
accountId: account._id,
|
|
210
205
|
params,
|
|
211
206
|
});
|
|
@@ -219,7 +214,7 @@ export default function password<DataModel extends GenericDataModel>(
|
|
|
219
214
|
}
|
|
220
215
|
// START: Optional, email verification during sign in
|
|
221
216
|
if (config.verify && !account.emailVerified) {
|
|
222
|
-
return await
|
|
217
|
+
return await ctx.auth.provider.signIn(ctx, config.verify, {
|
|
223
218
|
accountId: account._id,
|
|
224
219
|
params,
|
|
225
220
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configure {@link
|
|
2
|
+
* Configure {@link phone} provider given a {@link PhoneUserConfig}.
|
|
3
3
|
*
|
|
4
4
|
* Simplifies creating phone providers.
|
|
5
5
|
*
|
|
6
|
-
* By default checks that there is
|
|
6
|
+
* By default checks that there is a `phone` field during token verification
|
|
7
7
|
* that matches the `phone` used during the initial `signIn` call.
|
|
8
8
|
*
|
|
9
9
|
* @module
|