@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.
Files changed (67) hide show
  1. package/dist/client/index.d.ts +84 -30
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js +259 -59
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/component/index.d.ts +2 -2
  6. package/dist/component/index.d.ts.map +1 -1
  7. package/dist/component/index.js +2 -2
  8. package/dist/component/index.js.map +1 -1
  9. package/dist/providers/{Anonymous.d.ts → anonymous.d.ts} +8 -8
  10. package/dist/providers/{Anonymous.d.ts.map → anonymous.d.ts.map} +1 -1
  11. package/dist/providers/{Anonymous.js → anonymous.js} +9 -10
  12. package/dist/providers/anonymous.js.map +1 -0
  13. package/dist/providers/{ConvexCredentials.d.ts → credentials.d.ts} +11 -11
  14. package/dist/providers/credentials.d.ts.map +1 -0
  15. package/dist/providers/{ConvexCredentials.js → credentials.js} +8 -8
  16. package/dist/providers/credentials.js.map +1 -0
  17. package/dist/providers/{Email.d.ts → email.d.ts} +6 -6
  18. package/dist/providers/email.d.ts.map +1 -0
  19. package/dist/providers/{Email.js → email.js} +6 -6
  20. package/dist/providers/email.js.map +1 -0
  21. package/dist/providers/{Password.d.ts → password.d.ts} +10 -10
  22. package/dist/providers/{Password.d.ts.map → password.d.ts.map} +1 -1
  23. package/dist/providers/{Password.js → password.js} +19 -20
  24. package/dist/providers/password.js.map +1 -0
  25. package/dist/providers/{Phone.d.ts → phone.d.ts} +3 -3
  26. package/dist/providers/{Phone.d.ts.map → phone.d.ts.map} +1 -1
  27. package/dist/providers/{Phone.js → phone.js} +3 -3
  28. package/dist/providers/{Phone.js.map → phone.js.map} +1 -1
  29. package/dist/server/implementation/index.d.ts +73 -159
  30. package/dist/server/implementation/index.d.ts.map +1 -1
  31. package/dist/server/implementation/index.js +74 -100
  32. package/dist/server/implementation/index.js.map +1 -1
  33. package/dist/server/implementation/sessions.d.ts +2 -20
  34. package/dist/server/implementation/sessions.d.ts.map +1 -1
  35. package/dist/server/implementation/sessions.js +2 -20
  36. package/dist/server/implementation/sessions.js.map +1 -1
  37. package/dist/server/index.d.ts +18 -0
  38. package/dist/server/index.d.ts.map +1 -1
  39. package/dist/server/index.js +255 -0
  40. package/dist/server/index.js.map +1 -1
  41. package/dist/server/provider_utils.d.ts.map +1 -1
  42. package/dist/server/types.d.ts +70 -9
  43. package/dist/server/types.d.ts.map +1 -1
  44. package/package.json +3 -6
  45. package/src/client/index.ts +347 -110
  46. package/src/component/index.ts +1 -8
  47. package/src/providers/{Anonymous.ts → anonymous.ts} +10 -11
  48. package/src/providers/{ConvexCredentials.ts → credentials.ts} +11 -11
  49. package/src/providers/{Email.ts → email.ts} +5 -5
  50. package/src/providers/{Password.ts → password.ts} +22 -27
  51. package/src/providers/{Phone.ts → phone.ts} +2 -2
  52. package/src/server/implementation/index.ts +119 -231
  53. package/src/server/implementation/sessions.ts +2 -20
  54. package/src/server/index.ts +373 -0
  55. package/src/server/types.ts +95 -8
  56. package/dist/providers/Anonymous.js.map +0 -1
  57. package/dist/providers/ConvexCredentials.d.ts.map +0 -1
  58. package/dist/providers/ConvexCredentials.js.map +0 -1
  59. package/dist/providers/Email.d.ts.map +0 -1
  60. package/dist/providers/Email.js.map +0 -1
  61. package/dist/providers/Password.js.map +0 -1
  62. package/providers/Anonymous/package.json +0 -6
  63. package/providers/ConvexCredentials/package.json +0 -6
  64. package/providers/Email/package.json +0 -6
  65. package/providers/Password/package.json +0 -6
  66. package/providers/Phone/package.json +0 -6
  67. package/server/package.json +0 -6
@@ -1,22 +1,21 @@
1
1
  /**
2
- * Configure {@link Anonymous} provider given an {@link AnonymousConfig}.
2
+ * Configure {@link anonymous} provider given an {@link AnonymousConfig}.
3
3
  *
4
4
  * ```ts
5
- * import { Anonymous } from "@robelest/convex-auth/providers/Anonymous";
6
- * import { convexAuth } from "@robelest/convex-auth/component";
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 } = convexAuth({
9
- * providers: [Anonymous],
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 convexCredentials from "@robelest/convex-auth/providers/ConvexCredentials";
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 Anonymous} provider for Convex Auth.
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 Anonymous} providers.
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 convexCredentials<DataModel>({
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 createAccount(ctx, {
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 ConvexCredentials} provider given a {@link ConvexCredentialsUserConfig}.
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 [`Password`](https://labs.convex.dev/auth/api_reference/providers/Password) provider instead.
5
+ * use the [`password`](https://labs.convex.dev/auth/api_reference/providers/password) provider instead.
6
6
  *
7
7
  * ```ts
8
- * import ConvexCredentials from "@robelest/convex-auth/providers/ConvexCredentials";
9
- * import { convexAuth } from "@robelest/convex-auth/component";
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 } = convexAuth({
11
+ * export const { auth, signIn, signOut, store } = Auth({
12
12
  * providers: [
13
- * ConvexCredentials({
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 ConvexCredentials} provider for Convex Auth.
34
+ * The available options to a {@link credentials} provider for Convex Auth.
35
35
  */
36
- export interface ConvexCredentialsUserConfig<
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 ConvexCredentials} providers.
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 convexCredentials<DataModel extends GenericDataModel>(
99
- config: ConvexCredentialsUserConfig<DataModel>,
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 Email from "@robelest/convex-auth/providers/Email";
23
- * import { convexAuth } from "@robelest/convex-auth/component";
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 } = convexAuth({
25
+ * export const { auth, signIn, signOut, store } = Auth({
26
26
  * providers: [
27
- * Email({ authorize: undefined }),
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 Email<DataModel extends GenericDataModel>(
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 Password} provider given a {@link PasswordConfig}.
2
+ * Configure {@link password} provider given a {@link PasswordConfig}.
3
3
  *
4
- * The `Password` provider supports the following flows, determined
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 Password from "@robelest/convex-auth/providers/Password";
16
- * import { convexAuth } from "@robelest/convex-auth/component";
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 } = convexAuth({
19
- * providers: [Password],
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 convexCredentials, {
27
- ConvexCredentialsUserConfig,
28
- } from "@robelest/convex-auth/providers/ConvexCredentials";
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 Password} provider for Convex Auth.
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?: ConvexCredentialsUserConfig["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 convexCredentials<DataModel>({
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 createAccount(ctx, {
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 retrieveAccount(ctx, {
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 retrieveAccount(ctx, {
164
+ const { account } = await ctx.auth.account.get(ctx, {
170
165
  provider,
171
166
  account: { id: email },
172
167
  });
173
- return await signInViaProvider(ctx, config.reset, {
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 signInViaProvider(ctx, config.reset, { params });
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 modifyAccountCredentials(ctx, {
187
+ await ctx.auth.account.updateCredentials(ctx, {
193
188
  provider,
194
189
  account: { id: email, secret },
195
190
  });
196
- await invalidateSessions(ctx, { userId, except: [sessionId] });
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 retrieveAccount(ctx, {
199
+ const { account } = await ctx.auth.account.get(ctx, {
205
200
  provider,
206
201
  account: { id: email },
207
202
  });
208
- return await signInViaProvider(ctx, config.verify, {
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 signInViaProvider(ctx, config.verify, {
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 Phone} provider given a {@link PhoneUserConfig}.
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 an `phone` field during token verification
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