prostgles-client 4.0.421 → 4.0.424

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 (35) hide show
  1. package/dist/SyncedTable/SyncedTable.d.ts +4 -2
  2. package/dist/SyncedTable/SyncedTable.d.ts.map +1 -1
  3. package/dist/SyncedTable/createSync.d.ts +3 -6
  4. package/dist/SyncedTable/createSync.d.ts.map +1 -1
  5. package/dist/SyncedTable/createSync.js +83 -37
  6. package/dist/SyncedTable/createSyncDataStore.d.ts.map +1 -1
  7. package/dist/SyncedTable/createSyncDataStore.js +4 -2
  8. package/dist/SyncedTable/createSyncStateUtils.d.ts +8 -2
  9. package/dist/SyncedTable/createSyncStateUtils.d.ts.map +1 -1
  10. package/dist/SyncedTable/createSyncStateUtils.js +11 -12
  11. package/dist/SyncedTable/createSyncSubscriptionManager.d.ts +7 -5
  12. package/dist/SyncedTable/createSyncSubscriptionManager.d.ts.map +1 -1
  13. package/dist/SyncedTable/createSyncSubscriptionManager.js +45 -15
  14. package/dist/auth/authRequest.d.ts +7 -0
  15. package/dist/auth/authRequest.d.ts.map +1 -0
  16. package/dist/auth/authRequest.js +51 -0
  17. package/dist/auth/getAuthCalls.d.ts +7 -0
  18. package/dist/auth/getAuthCalls.d.ts.map +1 -0
  19. package/dist/auth/getAuthCalls.js +19 -0
  20. package/dist/auth/useAuthState.d.ts +340 -52
  21. package/dist/auth/useAuthState.d.ts.map +1 -1
  22. package/dist/auth/useAuthState.js +4 -1
  23. package/dist/getAuthHandler.d.ts +11 -15
  24. package/dist/getAuthHandler.d.ts.map +1 -1
  25. package/dist/getAuthHandler.js +14 -52
  26. package/dist/getDbHandler.d.ts +2 -2
  27. package/dist/getDbHandler.d.ts.map +1 -1
  28. package/dist/getDbHandler.js +4 -4
  29. package/dist/{getSyncHandlerV2.d.ts → getSyncHandler.d.ts} +4 -4
  30. package/dist/getSyncHandler.d.ts.map +1 -0
  31. package/dist/{getSyncHandlerV2.js → getSyncHandler.js} +18 -10
  32. package/dist/index.umd.js +1 -1
  33. package/dist/prostgles.js +3 -9
  34. package/package.json +5 -5
  35. package/dist/getSyncHandlerV2.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAuthCalls.d.ts","sourceRoot":"","sources":["../../lib/auth/getAuthCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAa,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,eAAO,MAAM,YAAY,GACvB,QAAQ,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC,EACjD,eAAe,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EACxC,SAAS,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,KACzC,eAeF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;KAC3B,SAAS,IAAI,aAAa,GAAG,CAC5B,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,KACtC,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;CAC5C,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuthCalls = void 0;
4
+ const authRequest_1 = require("./authRequest");
5
+ const getAuthCalls = (routes, getRequestURL, options) => {
6
+ const createCall = (operation) => async (data) => {
7
+ const route = routes[operation];
8
+ if (!route)
9
+ throw new Error("Unexpected");
10
+ return (0, authRequest_1.authRequest)(operation, getRequestURL(route), data, "POST", options);
11
+ };
12
+ return {
13
+ login: createCall("login"),
14
+ register: createCall("register"),
15
+ magicLinkOrOTP: createCall("magicLinkOrOTP"),
16
+ logout: createCall("logout"),
17
+ };
18
+ };
19
+ exports.getAuthCalls = getAuthCalls;
@@ -1,5 +1,4 @@
1
- import { type AuthResponse } from "prostgles-types";
2
- import type { AuthHandler, PasswordLogin, PasswordRegister } from "../getAuthHandler";
1
+ import type { AuthHandler } from "../getAuthHandler";
3
2
  export declare const useAuthState: ({ auth }: {
4
3
  auth: AuthHandler;
5
4
  }) => {
@@ -25,51 +24,255 @@ export declare const useAuthState: ({ auth }: {
25
24
  totpRecoveryCode: boolean;
26
25
  emailVerificationCode: boolean;
27
26
  };
28
- onCall: PasswordLogin | undefined;
27
+ onCall: ((data: import("prostgles-types").JSONB.GetObjectType<{
28
+ readonly remember_me: {
29
+ readonly type: "boolean";
30
+ readonly optional: true;
31
+ };
32
+ readonly totp_token: {
33
+ readonly type: "string";
34
+ readonly optional: true;
35
+ };
36
+ readonly totp_recovery_code: {
37
+ readonly type: "string";
38
+ readonly optional: true;
39
+ };
40
+ readonly username: "string";
41
+ readonly password: {
42
+ readonly type: "string";
43
+ readonly optional: true;
44
+ };
45
+ }>) => Promise<import("./authRequest").ClientAuthResponse<"login">>) | undefined;
29
46
  } | {
30
- onCall: PasswordRegister;
31
- result: (import("prostgles-types").CommonAuthFailure & {
47
+ onCall: (data: import("prostgles-types").JSONB.GetObjectType<{
48
+ readonly username: "string";
49
+ readonly password: {
50
+ readonly type: "string";
51
+ readonly optional: true;
52
+ };
53
+ }>) => Promise<import("./authRequest").ClientAuthResponse<"register">>;
54
+ result: ({
55
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong";
56
+ success: false;
57
+ } & {
58
+ message?: string | undefined;
59
+ } & {
60
+ redirect_url?: string;
61
+ }) | ({
62
+ success: true;
63
+ } & {
64
+ code?: undefined;
65
+ message?: string | undefined;
66
+ token?: string | undefined;
67
+ } & {
32
68
  redirect_url?: string;
33
69
  }) | ({
70
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
34
71
  success: false;
35
- code: "no-match";
36
- message?: string;
72
+ } & {
73
+ message?: string | undefined;
74
+ } & {
75
+ redirect_url?: string;
76
+ }) | ({
77
+ code: "email-verification-code-sent" | "magic-link-sent";
78
+ success: true;
79
+ } & {
80
+ message?: string | undefined;
37
81
  } & {
38
82
  redirect_url?: string;
39
83
  }) | ({
84
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
40
85
  success: false;
41
- code: "inactive-account";
42
- message?: string;
86
+ } & {
87
+ message?: string | undefined;
43
88
  } & {
44
89
  redirect_url?: string;
45
90
  }) | ({
91
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "provider-issue";
46
92
  success: false;
47
- code: "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
48
- message?: string;
93
+ } & {
94
+ message?: string | undefined;
49
95
  } & {
50
96
  redirect_url?: string;
51
- }) | (AuthResponse.AuthSuccess & {
97
+ }) | ({
98
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
99
+ success: false;
100
+ } & {
101
+ message?: string | undefined;
102
+ } & {
52
103
  redirect_url?: string;
53
- }) | (AuthResponse.MagicLinkAuthSuccess & {
104
+ }) | ({
105
+ code: "email-verification-code-sent" | "already-registered-but-did-not-confirm-email";
106
+ success: true;
107
+ } & {
108
+ message?: string | undefined;
109
+ } & {
54
110
  redirect_url?: string;
55
111
  }) | ({
112
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "inactive-account" | "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code";
56
113
  success: false;
57
- code: "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
58
- message?: string;
114
+ } & {
115
+ message?: string | undefined;
59
116
  } & {
60
117
  redirect_url?: string;
61
118
  }) | ({
119
+ success: true;
120
+ } & {
121
+ code?: undefined;
122
+ message?: string | undefined;
123
+ token?: string | undefined;
124
+ } & {
125
+ redirect_url?: string;
126
+ }) | ({
127
+ code: "email-verified";
128
+ success: true;
129
+ } & {
130
+ message?: string | undefined;
131
+ } & {
132
+ redirect_url?: string;
133
+ }) | ({
134
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
62
135
  success: false;
63
- code: "provider-issue";
64
- message?: string;
136
+ } & {
137
+ message?: string | undefined;
65
138
  } & {
66
139
  redirect_url?: string;
67
- }) | (AuthResponse.PasswordRegisterSuccess & {
140
+ }) | ({
141
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
142
+ success: false;
143
+ } & {
144
+ message?: string | undefined;
145
+ } & {
68
146
  redirect_url?: string;
69
147
  }) | ({
148
+ code: "invalid-email";
70
149
  success: false;
71
- code: "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code" | "inactive-account";
72
- message?: string;
150
+ } & {
151
+ message?: string | undefined;
152
+ } & {
153
+ redirect_url?: string;
154
+ }) | undefined;
155
+ state: "login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode";
156
+ username: string;
157
+ setUsername: import("react").Dispatch<import("react").SetStateAction<string>>;
158
+ password: string;
159
+ setPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
160
+ totpToken: string;
161
+ setTotpToken: import("react").Dispatch<import("react").SetStateAction<string>>;
162
+ totpRecoveryCode: string;
163
+ setTotpRecoveryCode: import("react").Dispatch<import("react").SetStateAction<string>>;
164
+ confirmPassword: string;
165
+ setConfirmPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
166
+ emailVerificationCode: string;
167
+ setEmailVerificationCode: import("react").Dispatch<import("react").SetStateAction<string>>;
168
+ show: {
169
+ username: boolean;
170
+ password: boolean;
171
+ confirmPassword: boolean;
172
+ totpCode: boolean;
173
+ totpRecoveryCode: boolean;
174
+ emailVerificationCode: boolean;
175
+ };
176
+ } | {
177
+ onCall: () => Promise<import("./authRequest").ClientAuthResponse<"magicLinkOrOTP">>;
178
+ result: ({
179
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong";
180
+ success: false;
181
+ } & {
182
+ message?: string | undefined;
183
+ } & {
184
+ redirect_url?: string;
185
+ }) | ({
186
+ success: true;
187
+ } & {
188
+ code?: undefined;
189
+ message?: string | undefined;
190
+ token?: string | undefined;
191
+ } & {
192
+ redirect_url?: string;
193
+ }) | ({
194
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
195
+ success: false;
196
+ } & {
197
+ message?: string | undefined;
198
+ } & {
199
+ redirect_url?: string;
200
+ }) | ({
201
+ code: "email-verification-code-sent" | "magic-link-sent";
202
+ success: true;
203
+ } & {
204
+ message?: string | undefined;
205
+ } & {
206
+ redirect_url?: string;
207
+ }) | ({
208
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
209
+ success: false;
210
+ } & {
211
+ message?: string | undefined;
212
+ } & {
213
+ redirect_url?: string;
214
+ }) | ({
215
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "provider-issue";
216
+ success: false;
217
+ } & {
218
+ message?: string | undefined;
219
+ } & {
220
+ redirect_url?: string;
221
+ }) | ({
222
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
223
+ success: false;
224
+ } & {
225
+ message?: string | undefined;
226
+ } & {
227
+ redirect_url?: string;
228
+ }) | ({
229
+ code: "email-verification-code-sent" | "already-registered-but-did-not-confirm-email";
230
+ success: true;
231
+ } & {
232
+ message?: string | undefined;
233
+ } & {
234
+ redirect_url?: string;
235
+ }) | ({
236
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "inactive-account" | "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code";
237
+ success: false;
238
+ } & {
239
+ message?: string | undefined;
240
+ } & {
241
+ redirect_url?: string;
242
+ }) | ({
243
+ success: true;
244
+ } & {
245
+ code?: undefined;
246
+ message?: string | undefined;
247
+ token?: string | undefined;
248
+ } & {
249
+ redirect_url?: string;
250
+ }) | ({
251
+ code: "email-verified";
252
+ success: true;
253
+ } & {
254
+ message?: string | undefined;
255
+ } & {
256
+ redirect_url?: string;
257
+ }) | ({
258
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
259
+ success: false;
260
+ } & {
261
+ message?: string | undefined;
262
+ } & {
263
+ redirect_url?: string;
264
+ }) | ({
265
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
266
+ success: false;
267
+ } & {
268
+ message?: string | undefined;
269
+ } & {
270
+ redirect_url?: string;
271
+ }) | ({
272
+ code: "invalid-email";
273
+ success: false;
274
+ } & {
275
+ message?: string | undefined;
73
276
  } & {
74
277
  redirect_url?: string;
75
278
  }) | undefined;
@@ -99,89 +302,171 @@ export declare const useAuthState: ({ auth }: {
99
302
  setState: import("react").Dispatch<import("react").SetStateAction<"login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode">>;
100
303
  state: "login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode";
101
304
  loading: boolean;
102
- onAuthCall: () => Promise<void | (import("prostgles-types").CommonAuthFailure & {
305
+ onAuthCall: () => Promise<void | ({
306
+ success: true;
307
+ } & {
308
+ code?: undefined;
309
+ message?: string | undefined;
310
+ token?: string | undefined;
311
+ } & {
103
312
  redirect_url?: string;
104
313
  }) | ({
314
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
105
315
  success: false;
106
- code: "no-match";
107
- message?: string;
316
+ } & {
317
+ message?: string | undefined;
108
318
  } & {
109
319
  redirect_url?: string;
110
320
  }) | ({
111
- success: false;
112
- code: "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
113
- message?: string;
321
+ code: "email-verification-code-sent" | "magic-link-sent";
322
+ success: true;
323
+ } & {
324
+ message?: string | undefined;
114
325
  } & {
115
326
  redirect_url?: string;
116
- }) | (AuthResponse.AuthSuccess & {
117
- redirect_url?: string;
118
- }) | (AuthResponse.MagicLinkAuthSuccess & {
327
+ }) | ({
328
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
329
+ success: false;
330
+ } & {
331
+ message?: string | undefined;
332
+ } & {
119
333
  redirect_url?: string;
120
334
  }) | ({
335
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "provider-issue";
121
336
  success: false;
122
- code: "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
123
- message?: string;
337
+ } & {
338
+ message?: string | undefined;
124
339
  } & {
125
340
  redirect_url?: string;
126
341
  }) | ({
342
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
127
343
  success: false;
128
- code: "provider-issue";
129
- message?: string;
344
+ } & {
345
+ message?: string | undefined;
130
346
  } & {
131
347
  redirect_url?: string;
132
- }) | (AuthResponse.PasswordRegisterSuccess & {
348
+ }) | ({
349
+ code: "email-verification-code-sent" | "already-registered-but-did-not-confirm-email";
350
+ success: true;
351
+ } & {
352
+ message?: string | undefined;
353
+ } & {
133
354
  redirect_url?: string;
134
355
  }) | ({
356
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "inactive-account" | "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code";
135
357
  success: false;
136
- code: "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code" | "inactive-account";
137
- message?: string;
358
+ } & {
359
+ message?: string | undefined;
360
+ } & {
361
+ redirect_url?: string;
362
+ }) | ({
363
+ code: "email-verified";
364
+ success: true;
365
+ } & {
366
+ message?: string | undefined;
138
367
  } & {
139
368
  redirect_url?: string;
140
369
  })>;
141
370
  isOnLogin: boolean;
142
371
  registerTypeAllowed: "registerWithPassword";
143
- result: (import("prostgles-types").CommonAuthFailure & {
372
+ result: ({
373
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong";
374
+ success: false;
375
+ } & {
376
+ message?: string | undefined;
377
+ } & {
144
378
  redirect_url?: string;
145
379
  }) | ({
380
+ success: true;
381
+ } & {
382
+ code?: undefined;
383
+ message?: string | undefined;
384
+ token?: string | undefined;
385
+ } & {
386
+ redirect_url?: string;
387
+ }) | ({
388
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
146
389
  success: false;
147
- code: "no-match";
148
- message?: string;
390
+ } & {
391
+ message?: string | undefined;
149
392
  } & {
150
393
  redirect_url?: string;
151
394
  }) | ({
395
+ code: "email-verification-code-sent" | "magic-link-sent";
396
+ success: true;
397
+ } & {
398
+ message?: string | undefined;
399
+ } & {
400
+ redirect_url?: string;
401
+ }) | ({
402
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
152
403
  success: false;
153
- code: "inactive-account";
154
- message?: string;
404
+ } & {
405
+ message?: string | undefined;
155
406
  } & {
156
407
  redirect_url?: string;
157
408
  }) | ({
409
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "provider-issue";
158
410
  success: false;
159
- code: "totp-token-missing" | "invalid-username" | "username-missing" | "invalid-email" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
160
- message?: string;
411
+ } & {
412
+ message?: string | undefined;
161
413
  } & {
162
414
  redirect_url?: string;
163
- }) | (AuthResponse.AuthSuccess & {
415
+ }) | ({
416
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
417
+ success: false;
418
+ } & {
419
+ message?: string | undefined;
420
+ } & {
164
421
  redirect_url?: string;
165
- }) | (AuthResponse.MagicLinkAuthSuccess & {
422
+ }) | ({
423
+ code: "email-verification-code-sent" | "already-registered-but-did-not-confirm-email";
424
+ success: true;
425
+ } & {
426
+ message?: string | undefined;
427
+ } & {
166
428
  redirect_url?: string;
167
429
  }) | ({
430
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "inactive-account" | "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code";
168
431
  success: false;
169
- code: "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
170
- message?: string;
432
+ } & {
433
+ message?: string | undefined;
434
+ } & {
435
+ redirect_url?: string;
436
+ }) | ({
437
+ success: true;
438
+ } & {
439
+ code?: undefined;
440
+ message?: string | undefined;
441
+ token?: string | undefined;
442
+ } & {
443
+ redirect_url?: string;
444
+ }) | ({
445
+ code: "email-verified";
446
+ success: true;
447
+ } & {
448
+ message?: string | undefined;
171
449
  } & {
172
450
  redirect_url?: string;
173
451
  }) | ({
452
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
174
453
  success: false;
175
- code: "provider-issue";
176
- message?: string;
454
+ } & {
455
+ message?: string | undefined;
177
456
  } & {
178
457
  redirect_url?: string;
179
- }) | (AuthResponse.PasswordRegisterSuccess & {
458
+ }) | ({
459
+ code: "server-error" | "rate-limit-exceeded" | "something-went-wrong" | "no-match" | "inactive-account" | "invalid-otp-code" | "expired-otp-code";
460
+ success: false;
461
+ } & {
462
+ message?: string | undefined;
463
+ } & {
180
464
  redirect_url?: string;
181
465
  }) | ({
466
+ code: "invalid-email";
182
467
  success: false;
183
- code: "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code" | "inactive-account";
184
- message?: string;
468
+ } & {
469
+ message?: string | undefined;
185
470
  } & {
186
471
  redirect_url?: string;
187
472
  }) | undefined;
@@ -215,5 +500,8 @@ export declare const ERR_CODE_MESSAGES: {
215
500
  "invalid-magic-link": string;
216
501
  "used-magic-link": string;
217
502
  "invalid-email": string;
503
+ "invalid-otp-code": string;
504
+ "expired-otp-code": string;
505
+ "provider-issue": string;
218
506
  };
219
507
  //# sourceMappingURL=useAuthState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../lib/auth/useAuthState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG1E,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;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa/C,OAAO;iBACP,MAAM;;;CAoNlB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmC7B,CAAC"}
@@ -163,7 +163,7 @@ const useAuthState = ({ auth }) => {
163
163
  }
164
164
  else if (res.code !== "password-missing") {
165
165
  const errorMessage = res.message ?? (0, prostgles_types_1.getProperty)(exports.ERR_CODE_MESSAGES, res.code);
166
- setErrorWithInfo(errorMessage ?? "Error");
166
+ setErrorWithInfo(errorMessage);
167
167
  }
168
168
  }
169
169
  else {
@@ -233,6 +233,9 @@ exports.ERR_CODE_MESSAGES = {
233
233
  "invalid-magic-link": "Invalid magic link",
234
234
  "used-magic-link": "Magic link already used",
235
235
  "invalid-email": "Invalid or missing email",
236
+ "invalid-otp-code": "Invalid code",
237
+ "expired-otp-code": "Code expired",
238
+ "provider-issue": "Authentication provider error",
236
239
  };
237
240
  const SIGNUP_CODE_MESSAGES = {
238
241
  "already-registered-but-did-not-confirm-email": "Email verification re-sent. Open the verification url or enter the code to confirm your email",
@@ -1,6 +1,9 @@
1
- import type { AuthRequest, AuthResponse, AuthSocketSchema, IdentityProvider, LocalLoginMode, UserLike } from "prostgles-types";
1
+ import type { AuthRequest, AuthSocketSchema, IdentityProvider, LocalLoginMode, UserLike } from "prostgles-types";
2
2
  import { type InitOptions } from "./prostgles";
3
3
  import type { Socket } from "socket.io-client";
4
+ import type { ClientAuthResponse } from "./auth/authRequest";
5
+ import { type ClientAuthCalls } from "./auth/getAuthCalls";
6
+ export { authRequest } from "./auth/authRequest";
4
7
  type OptionalToUndefined<T> = {
5
8
  [K in {} & keyof T]: T[K];
6
9
  };
@@ -11,22 +14,17 @@ type Args = Pick<OptionalToUndefined<InitOptions>, "credentials" | "redirect"> &
11
14
  endpoint: string | undefined;
12
15
  };
13
16
  type WithProviderLogin = Partial<Record<IdentityProvider, VoidFunction>>;
14
- type ClientAuthSuccess<T> = T & {
15
- /**
16
- * This is a client-only property that is obtained from server redirect response
17
- */
18
- redirect_url?: string;
19
- };
20
- export type PasswordLoginResponse = ClientAuthSuccess<AuthResponse.PasswordLoginFailure | AuthResponse.PasswordLoginSuccess | AuthResponse.MagicLinkAuthSuccess | AuthResponse.MagicLinkAuthFailure | AuthResponse.OAuthRegisterSuccess | AuthResponse.OAuthRegisterFailure>;
21
- export type PasswordRegisterResponse = ClientAuthSuccess<AuthResponse.PasswordRegisterSuccess | AuthResponse.PasswordRegisterFailure>;
22
- export type PasswordRegister = (params: AuthRequest.RegisterData) => Promise<PasswordRegisterResponse>;
23
- export type PasswordLogin = (params: AuthRequest.LoginData) => Promise<PasswordLoginResponse>;
17
+ export type PasswordLoginResponse = ClientAuthResponse<"login">;
18
+ export type PasswordRegisterResponse = ClientAuthResponse<"register">;
19
+ export type PasswordRegister = ClientAuthCalls["register"];
20
+ export type PasswordLogin = ClientAuthCalls["login"];
21
+ export type ConfirmEmail = (data: AuthRequest.ConfirmEmailData) => Promise<ClientAuthResponse<"magicLinkOrOTP">>;
24
22
  type LoginSignupOptions = Pick<AuthSocketSchema, "providers" | "preferredLogin"> & {
25
23
  loginWithProvider: undefined | WithProviderLogin;
26
24
  login: undefined | PasswordLogin;
27
25
  loginType: LocalLoginMode | undefined;
28
26
  signupWithEmailAndPassword: undefined | PasswordRegister;
29
- confirmEmail: undefined | ((data: AuthRequest.ConfirmEmailData) => Promise<PasswordRegisterResponse>);
27
+ confirmEmail: undefined | ConfirmEmail;
30
28
  };
31
29
  type AuthStateLoggedOut = LoginSignupOptions & {
32
30
  isLoggedin: false;
@@ -35,10 +33,8 @@ type AuthStateLoggedOut = LoginSignupOptions & {
35
33
  type AuthStateLoggedIn<U extends UserLike = UserLike> = LoginSignupOptions & {
36
34
  isLoggedin: true;
37
35
  user: U;
38
- logout: () => Promise<any>;
36
+ logout: () => Promise<ClientAuthResponse<"logout">>;
39
37
  };
40
38
  export type AuthHandler<U extends UserLike = UserLike> = AuthStateLoggedOut | AuthStateLoggedIn<U>;
41
39
  export declare const getAuthHandler: ({ authData: authConfig, socket, onReload, endpoint, ...authOpts }: Args) => AuthHandler;
42
- export declare const authRequest: <T extends PasswordRegisterResponse | PasswordLoginResponse>(path: string, data: object, method: "GET" | "POST", { credentials, redirect }: Pick<Partial<Request>, "credentials" | "redirect">) => Promise<T>;
43
- export {};
44
40
  //# sourceMappingURL=getAuthHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAuthHandler.d.ts","sourceRoot":"","sources":["../lib/getAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5D,KAAK,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,aAAa,GAAG,UAAU,CAAC,GAAG;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF,KAAK,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzE,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG;IAC9B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,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