prostgles-client 4.0.395 → 4.0.398
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/auth/useAuthState.d.ts +33 -110
- package/dist/auth/useAuthState.d.ts.map +1 -1
- package/dist/auth/useAuthState.js +48 -50
- package/package.json +1 -1
|
@@ -4,61 +4,29 @@ export declare const useAuthState: ({ auth }: {
|
|
|
4
4
|
auth: AuthHandler;
|
|
5
5
|
}) => {
|
|
6
6
|
formHandlers: {
|
|
7
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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,
|
|
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"}
|
|
@@ -30,58 +30,54 @@ const useAuthState = ({ auth }) => {
|
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
_setError("");
|
|
32
32
|
}, [username, password, totpToken, totpRecoveryCode, confirmPassword]);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
username,
|
|
83
|
-
emailVerificationCode,
|
|
84
|
-
setEmailVerificationCode,
|
|
80
|
+
...commonFormHandlers,
|
|
85
81
|
onCall: () => {
|
|
86
82
|
if (!auth.confirmEmail) {
|
|
87
83
|
throw new Error("unexpected");
|
|
@@ -96,13 +92,15 @@ const useAuthState = ({ auth }) => {
|
|
|
96
92
|
: undefined;
|
|
97
93
|
const isOnLogin = loginStates.some((v) => v === state);
|
|
98
94
|
const registerTypeAllowed = "registerWithPassword";
|
|
95
|
+
const shownKeys = (0, prostgles_types_1.getKeys)(show).filter((key) => show[key]);
|
|
96
|
+
const isOnlyShowingUsername = shownKeys[0] === "username" && shownKeys.length === 1;
|
|
99
97
|
const onAuthCall = async () => {
|
|
100
98
|
const formData = {
|
|
101
99
|
username,
|
|
102
|
-
password,
|
|
100
|
+
password: isOnlyShowingUsername ? undefined : password,
|
|
103
101
|
remember_me: false,
|
|
104
|
-
totp_token: totpToken,
|
|
105
|
-
totp_recovery_code: totpRecoveryCode,
|
|
102
|
+
totp_token: isOnlyShowingUsername ? undefined : totpToken,
|
|
103
|
+
totp_recovery_code: isOnlyShowingUsername ? undefined : totpRecoveryCode,
|
|
106
104
|
};
|
|
107
105
|
const errorMap = {
|
|
108
106
|
"no match": "Invalid credentials",
|
|
@@ -123,7 +121,7 @@ const useAuthState = ({ auth }) => {
|
|
|
123
121
|
if (!username) {
|
|
124
122
|
return setError("Username/email cannot be empty");
|
|
125
123
|
}
|
|
126
|
-
if (!password &&
|
|
124
|
+
if (!password && show.password) {
|
|
127
125
|
return setError("Password cannot be empty");
|
|
128
126
|
}
|
|
129
127
|
if (formHandlers.state === "loginTotp" && !totpToken) {
|
|
@@ -172,7 +170,7 @@ const useAuthState = ({ auth }) => {
|
|
|
172
170
|
if ("redirect_url" in res && res.redirect_url) {
|
|
173
171
|
window.location.href = res.redirect_url;
|
|
174
172
|
}
|
|
175
|
-
if (state === "registerWithPassword"
|
|
173
|
+
if (state === "registerWithPassword") {
|
|
176
174
|
setState("registerWithPasswordConfirmationCode");
|
|
177
175
|
}
|
|
178
176
|
let message = (res.code && SIGNUP_CODE_MESSAGES[res.code]) ?? res.message ?? "Success";
|