prostgles-client 4.0.422 → 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.
@@ -0,0 +1,7 @@
1
+ import { type AuthInput, type AuthOperation, type AuthOutput, type CommonAuthFailure } from "prostgles-types";
2
+ export declare const authRequest: <Operation extends AuthOperation>(operation: Operation, path: string, data: AuthInput<Operation>, method: "GET" | "POST", { credentials, redirect }: Pick<Partial<Request>, "credentials" | "redirect">) => Promise<ClientAuthResponse<Operation>>;
3
+ export type ClientAuthResponse<Operation extends AuthOperation> = (AuthOutput<Operation> | CommonAuthFailure) & {
4
+ /** Obtained from the HTTP redirect, rather than the response body. */
5
+ redirect_url?: string;
6
+ };
7
+ //# sourceMappingURL=authRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authRequest.d.ts","sourceRoot":"","sources":["../../lib/auth/authRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,WAAW,GAAU,SAAS,SAAS,aAAa,EAC/D,WAAW,SAAS,EACpB,MAAM,MAAM,EACZ,MAAM,SAAS,CAAC,SAAS,CAAC,EAC1B,QAAQ,KAAK,GAAG,MAAM,EACtB,2BAA2B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,UAAU,CAAC,KAC5E,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAqDvC,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,SAAS,SAAS,aAAa,IAAI,CAC9D,UAAU,CAAC,SAAS,CAAC,GACrB,iBAAiB,CACpB,GAAG;IACF,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authRequest = void 0;
4
+ const prostgles_types_1 = require("prostgles-types");
5
+ const authRequest = async (operation, path, data, method, { credentials, redirect }) => {
6
+ const rawResponse = await fetch(path, {
7
+ method,
8
+ headers: {
9
+ Accept: "application/json",
10
+ "Content-Type": "application/json",
11
+ },
12
+ ...(method !== "GET" && { body: JSON.stringify(data) }),
13
+ credentials,
14
+ redirect,
15
+ });
16
+ const responseText = await rawResponse.text();
17
+ let response;
18
+ try {
19
+ response = JSON.parse(responseText);
20
+ }
21
+ catch {
22
+ if (rawResponse.ok && rawResponse.redirected) {
23
+ response = { success: true };
24
+ }
25
+ else {
26
+ return {
27
+ success: false,
28
+ code: "something-went-wrong",
29
+ message: responseText || rawResponse.statusText,
30
+ };
31
+ }
32
+ }
33
+ if (rawResponse.ok &&
34
+ rawResponse.redirected &&
35
+ (!(0, prostgles_types_1.isObject)(response) || !("success" in response))) {
36
+ response = { success: true };
37
+ }
38
+ const validation = (0, prostgles_types_1.getJSONBSchemaValidationError)(prostgles_types_1.authContract[operation].response, response, { allowExtraProperties: true });
39
+ if (validation.error !== undefined || (!rawResponse.ok && validation.data.success)) {
40
+ return {
41
+ success: false,
42
+ code: "something-went-wrong",
43
+ message: "Unexpected authentication response was sent by the server: " + validation.error,
44
+ };
45
+ }
46
+ return {
47
+ ...validation.data,
48
+ ...(rawResponse.redirected && { redirect_url: rawResponse.url }),
49
+ };
50
+ };
51
+ exports.authRequest = authRequest;
@@ -0,0 +1,7 @@
1
+ import type { AuthCalls, AuthOperation } from "prostgles-types";
2
+ import { authRequest, type ClientAuthResponse } from "./authRequest";
3
+ export declare const getAuthCalls: (routes: Record<AuthOperation, string | undefined>, getRequestURL: (route: string) => string, options: Parameters<typeof authRequest>[4]) => ClientAuthCalls;
4
+ export type ClientAuthCalls = {
5
+ [Operation in AuthOperation]: (...args: Parameters<AuthCalls[Operation]>) => Promise<ClientAuthResponse<Operation>>;
6
+ };
7
+ //# sourceMappingURL=getAuthCalls.d.ts.map
@@ -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,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AA2BtF,eAAO,MAAM,YAAY,GAAI,UAAU;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa/C,OAAO;iBACP,MAAM;;;CAoNlB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;CA8B7B,CAAC"}
1
+ {"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../lib/auth/useAuthState.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAiD,MAAM,mBAAmB,CAAC;AA6BpG,eAAO,MAAM,YAAY,GAAI,UAAU;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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",