prostgles-client 4.0.395 → 4.0.397

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.
@@ -4,61 +4,29 @@ export declare const useAuthState: ({ auth }: {
4
4
  auth: AuthHandler;
5
5
  }) => {
6
6
  formHandlers: {
7
- onCall: PasswordLogin | undefined;
8
- password?: string | undefined;
9
- setPassword?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
10
- state: "login";
7
+ state: "login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode";
11
8
  username: string;
12
9
  setUsername: import("react").Dispatch<import("react").SetStateAction<string>>;
13
- totpToken?: undefined;
14
- setTotpToken?: undefined;
15
- totpRecoveryCode?: undefined;
16
- setTotpRecoveryCode?: undefined;
17
- confirmPassword?: undefined;
18
- setConfirmPassword?: undefined;
19
- result?: undefined;
20
- emailVerificationCode?: undefined;
21
- setEmailVerificationCode?: undefined;
22
- } | {
23
- state: "loginTotp";
10
+ password: string;
11
+ setPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
24
12
  totpToken: string;
25
13
  setTotpToken: import("react").Dispatch<import("react").SetStateAction<string>>;
26
- onCall: PasswordLogin;
27
- totpRecoveryCode?: undefined;
28
- setTotpRecoveryCode?: undefined;
29
- username?: undefined;
30
- setUsername?: undefined;
31
- password?: undefined;
32
- setPassword?: undefined;
33
- confirmPassword?: undefined;
34
- setConfirmPassword?: undefined;
35
- result?: undefined;
36
- emailVerificationCode?: undefined;
37
- setEmailVerificationCode?: undefined;
38
- } | {
39
- state: "loginTotpRecovery";
40
14
  totpRecoveryCode: string;
41
15
  setTotpRecoveryCode: import("react").Dispatch<import("react").SetStateAction<string>>;
42
- onCall: PasswordLogin;
43
- totpToken?: undefined;
44
- setTotpToken?: undefined;
45
- username?: undefined;
46
- setUsername?: undefined;
47
- password?: undefined;
48
- setPassword?: undefined;
49
- confirmPassword?: undefined;
50
- setConfirmPassword?: undefined;
51
- result?: undefined;
52
- emailVerificationCode?: undefined;
53
- setEmailVerificationCode?: undefined;
54
- } | {
55
- state: "registerWithPassword";
56
- username: string;
57
- setUsername: import("react").Dispatch<import("react").SetStateAction<string>>;
58
- password: string;
59
- setPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
60
16
  confirmPassword: string;
61
17
  setConfirmPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
18
+ emailVerificationCode: string;
19
+ setEmailVerificationCode: import("react").Dispatch<import("react").SetStateAction<string>>;
20
+ show: {
21
+ username: boolean;
22
+ password: boolean;
23
+ confirmPassword: boolean;
24
+ totpCode: boolean;
25
+ totpRecoveryCode: boolean;
26
+ emailVerificationCode: boolean;
27
+ };
28
+ onCall: PasswordLogin | undefined;
29
+ } | {
62
30
  onCall: PasswordRegister;
63
31
  result: (import("prostgles-types").CommonAuthFailure & {
64
32
  redirect_url?: string;
@@ -105,72 +73,27 @@ export declare const useAuthState: ({ auth }: {
105
73
  } & {
106
74
  redirect_url?: string;
107
75
  }) | undefined;
108
- totpToken?: undefined;
109
- setTotpToken?: undefined;
110
- totpRecoveryCode?: undefined;
111
- setTotpRecoveryCode?: undefined;
112
- emailVerificationCode?: undefined;
113
- setEmailVerificationCode?: undefined;
114
- } | {
115
- state: "registerWithPasswordConfirmationCode";
76
+ state: "login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode";
116
77
  username: string;
78
+ setUsername: import("react").Dispatch<import("react").SetStateAction<string>>;
79
+ password: string;
80
+ setPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
81
+ totpToken: string;
82
+ setTotpToken: import("react").Dispatch<import("react").SetStateAction<string>>;
83
+ totpRecoveryCode: string;
84
+ setTotpRecoveryCode: import("react").Dispatch<import("react").SetStateAction<string>>;
85
+ confirmPassword: string;
86
+ setConfirmPassword: import("react").Dispatch<import("react").SetStateAction<string>>;
117
87
  emailVerificationCode: string;
118
88
  setEmailVerificationCode: import("react").Dispatch<import("react").SetStateAction<string>>;
119
- onCall: () => Promise<import("../getAuthHandler").PasswordRegisterResponse>;
120
- result: (import("prostgles-types").CommonAuthFailure & {
121
- redirect_url?: string;
122
- }) | ({
123
- success: false;
124
- code: "no-match";
125
- message?: string;
126
- } & {
127
- redirect_url?: string;
128
- }) | ({
129
- success: false;
130
- code: "inactive-account";
131
- message?: string;
132
- } & {
133
- redirect_url?: string;
134
- }) | ({
135
- success: false;
136
- 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";
137
- message?: string;
138
- } & {
139
- redirect_url?: string;
140
- }) | (AuthResponse.AuthSuccess & {
141
- redirect_url?: string;
142
- }) | (AuthResponse.MagicLinkAuthSuccess & {
143
- redirect_url?: string;
144
- }) | ({
145
- success: false;
146
- code: "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
147
- message?: string;
148
- } & {
149
- redirect_url?: string;
150
- }) | ({
151
- success: false;
152
- code: "provider-issue";
153
- message?: string;
154
- } & {
155
- redirect_url?: string;
156
- }) | (AuthResponse.PasswordRegisterSuccess & {
157
- redirect_url?: string;
158
- }) | ({
159
- success: false;
160
- code: "username-missing" | "password-missing" | "weak-password" | "user-already-registered" | "invalid-email-confirmation-code" | "expired-email-confirmation-code" | "inactive-account";
161
- message?: string;
162
- } & {
163
- redirect_url?: string;
164
- }) | undefined;
165
- totpToken?: undefined;
166
- setTotpToken?: undefined;
167
- totpRecoveryCode?: undefined;
168
- setTotpRecoveryCode?: undefined;
169
- setUsername?: undefined;
170
- password?: undefined;
171
- setPassword?: undefined;
172
- confirmPassword?: undefined;
173
- setConfirmPassword?: undefined;
89
+ show: {
90
+ username: boolean;
91
+ password: boolean;
92
+ confirmPassword: boolean;
93
+ totpCode: boolean;
94
+ totpRecoveryCode: boolean;
95
+ emailVerificationCode: boolean;
96
+ };
174
97
  } | undefined;
175
98
  error: string;
176
99
  setState: import("react").Dispatch<import("react").SetStateAction<"login" | "loginTotp" | "loginTotpRecovery" | "registerWithPassword" | "registerWithPasswordConfirmationCode">>;
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../lib/auth/useAuthState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGjE,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;;;CA2MlB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;CA8B7B,CAAC"}
1
+ {"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../lib/auth/useAuthState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGjE,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;;;CAkNlB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;CA8B7B,CAAC"}
@@ -30,58 +30,54 @@ const useAuthState = ({ auth }) => {
30
30
  useEffect(() => {
31
31
  _setError("");
32
32
  }, [username, password, totpToken, totpRecoveryCode, confirmPassword]);
33
- const formHandlers = state === "login" && auth.loginType === "email" ?
34
- {
35
- state,
36
- username,
37
- setUsername,
38
- ...(usernamesWithPassword.includes(username) && {
39
- password,
40
- setPassword,
41
- }),
42
- onCall: auth.login,
43
- }
44
- : state === "login" && auth.loginType === "email+password" ?
45
- {
46
- state,
47
- username,
48
- setUsername,
49
- password,
50
- setPassword,
51
- onCall: auth.login,
52
- }
53
- : state === "loginTotp" && auth.login ?
54
- {
55
- state,
56
- totpToken,
57
- setTotpToken,
58
- onCall: auth.login,
59
- }
60
- : state === "loginTotpRecovery" && auth.login ?
61
- {
62
- state,
63
- totpRecoveryCode,
64
- setTotpRecoveryCode,
65
- onCall: auth.login,
66
- }
33
+ const showPassword = (state === "registerWithPassword" && auth.signupWithEmailAndPassword) ||
34
+ (state === "login" && auth.loginType === "email" && usernamesWithPassword.includes(username)) ||
35
+ (state === "login" && auth.loginType === "email+password");
36
+ const showUsername = (state === "registerWithPassword" && auth.signupWithEmailAndPassword) ||
37
+ (state === "login" && auth.loginType === "email") ||
38
+ (state === "login" && auth.loginType === "email+password");
39
+ const showConfirmPassword = state === "registerWithPassword" && auth.signupWithEmailAndPassword;
40
+ const showTotpCode = state === "loginTotp" && auth.login;
41
+ const showTotpRecoveryCode = state === "loginTotpRecovery" && auth.login;
42
+ const showEmailVerificationCode = state === "registerWithPasswordConfirmationCode" && auth.signupWithEmailAndPassword;
43
+ const show = {
44
+ username: Boolean(showUsername),
45
+ password: Boolean(showPassword),
46
+ confirmPassword: Boolean(showConfirmPassword),
47
+ totpCode: Boolean(showTotpCode),
48
+ totpRecoveryCode: Boolean(showTotpRecoveryCode),
49
+ emailVerificationCode: Boolean(showEmailVerificationCode),
50
+ };
51
+ const commonFormHandlers = {
52
+ state,
53
+ username,
54
+ setUsername,
55
+ password,
56
+ setPassword,
57
+ totpToken,
58
+ setTotpToken,
59
+ totpRecoveryCode,
60
+ setTotpRecoveryCode,
61
+ confirmPassword,
62
+ setConfirmPassword,
63
+ emailVerificationCode,
64
+ setEmailVerificationCode,
65
+ show,
66
+ onCall: auth.login,
67
+ };
68
+ const formHandlers = state === "login" && auth.loginType === "email" ? commonFormHandlers
69
+ : state === "login" && auth.loginType === "email+password" ? commonFormHandlers
70
+ : state === "loginTotp" && auth.login ? commonFormHandlers
71
+ : state === "loginTotpRecovery" && auth.login ? commonFormHandlers
67
72
  : state === "registerWithPassword" && auth.signupWithEmailAndPassword ?
68
73
  {
69
- state,
70
- username,
71
- setUsername,
72
- password,
73
- setPassword,
74
- confirmPassword,
75
- setConfirmPassword,
74
+ ...commonFormHandlers,
76
75
  onCall: auth.signupWithEmailAndPassword,
77
76
  result,
78
77
  }
79
78
  : state === "registerWithPasswordConfirmationCode" && auth.signupWithEmailAndPassword ?
80
79
  {
81
- state,
82
- username,
83
- emailVerificationCode,
84
- setEmailVerificationCode,
80
+ ...commonFormHandlers,
85
81
  onCall: () => {
86
82
  if (!auth.confirmEmail) {
87
83
  throw new Error("unexpected");
@@ -123,7 +119,7 @@ const useAuthState = ({ auth }) => {
123
119
  if (!username) {
124
120
  return setError("Username/email cannot be empty");
125
121
  }
126
- if (!password && formHandlers.setPassword) {
122
+ if (!password && show.password) {
127
123
  return setError("Password cannot be empty");
128
124
  }
129
125
  if (formHandlers.state === "loginTotp" && !totpToken) {
@@ -172,7 +168,7 @@ const useAuthState = ({ auth }) => {
172
168
  if ("redirect_url" in res && res.redirect_url) {
173
169
  window.location.href = res.redirect_url;
174
170
  }
175
- if (state === "registerWithPassword" || res.code === "magic-link-sent") {
171
+ if (state === "registerWithPassword") {
176
172
  setState("registerWithPasswordConfirmationCode");
177
173
  }
178
174
  let message = (res.code && SIGNUP_CODE_MESSAGES[res.code]) ?? res.message ?? "Success";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-client",
3
- "version": "4.0.395",
3
+ "version": "4.0.397",
4
4
  "description": "Reactive client for Postgres",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",