@xouteiro/auth_npm 1.0.9 → 1.0.11
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/package.json
CHANGED
|
@@ -46,6 +46,24 @@ const buttonStyle = {
|
|
|
46
46
|
cursor: 'pointer',
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
const toggleButtonStyle = {
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
right: 16,
|
|
52
|
+
top: '50%',
|
|
53
|
+
transform: 'translateY(-50%)',
|
|
54
|
+
background: 'none',
|
|
55
|
+
border: 'none',
|
|
56
|
+
color: '#0070f3',
|
|
57
|
+
cursor: 'pointer',
|
|
58
|
+
fontSize: 14,
|
|
59
|
+
padding: 0,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const inputWrapperStyle = {
|
|
63
|
+
position: 'relative',
|
|
64
|
+
width: '100%',
|
|
65
|
+
};
|
|
66
|
+
|
|
49
67
|
const messageStyle = (success) => ({
|
|
50
68
|
margin: '12px 0',
|
|
51
69
|
color: success ? '#0a0' : '#d32f2f',
|
|
@@ -60,18 +78,20 @@ export default function LoginRegisterFlow({ onLoginSuccess, onRegisterSuccess })
|
|
|
60
78
|
const [mode, setMode] = useState('login');
|
|
61
79
|
const [identifier, setIdentifier] = useState('');
|
|
62
80
|
const [password, setPassword] = useState('');
|
|
63
|
-
const [
|
|
64
|
-
const [phone, setPhone] = useState('');
|
|
81
|
+
const [confirmPassword, setConfirmPassword] = useState('');
|
|
65
82
|
const [message, setMessage] = useState(null);
|
|
66
83
|
const [success, setSuccess] = useState(false);
|
|
84
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
85
|
+
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
|
67
86
|
|
|
68
87
|
const resetFields = () => {
|
|
69
88
|
setIdentifier('');
|
|
70
89
|
setPassword('');
|
|
71
|
-
|
|
72
|
-
setPhone('');
|
|
90
|
+
setConfirmPassword('');
|
|
73
91
|
setMessage(null);
|
|
74
92
|
setSuccess(false);
|
|
93
|
+
setShowPassword(false);
|
|
94
|
+
setShowConfirmPassword(false);
|
|
75
95
|
};
|
|
76
96
|
|
|
77
97
|
const handleLogin = async (e) => {
|
|
@@ -94,7 +114,12 @@ export default function LoginRegisterFlow({ onLoginSuccess, onRegisterSuccess })
|
|
|
94
114
|
e.preventDefault();
|
|
95
115
|
setMessage(null);
|
|
96
116
|
setSuccess(false);
|
|
97
|
-
|
|
117
|
+
if (password !== confirmPassword) {
|
|
118
|
+
setMessage("Passwords do not match");
|
|
119
|
+
setSuccess(false);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const { user, error } = await registerWithEmail(identifier, password);
|
|
98
123
|
if (error) {
|
|
99
124
|
setMessage(error.message || 'Registration failed');
|
|
100
125
|
setSuccess(false);
|
|
@@ -117,19 +142,29 @@ export default function LoginRegisterFlow({ onLoginSuccess, onRegisterSuccess })
|
|
|
117
142
|
<input
|
|
118
143
|
style={inputStyle}
|
|
119
144
|
type="text"
|
|
120
|
-
placeholder="Email
|
|
145
|
+
placeholder="Email"
|
|
121
146
|
value={identifier}
|
|
122
147
|
onChange={e => setIdentifier(e.target.value)}
|
|
123
148
|
required
|
|
124
149
|
/>
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
<div style={inputWrapperStyle}>
|
|
151
|
+
<input
|
|
152
|
+
style={inputStyle}
|
|
153
|
+
type={showPassword ? "text" : "password"}
|
|
154
|
+
placeholder="Password"
|
|
155
|
+
value={password}
|
|
156
|
+
onChange={e => setPassword(e.target.value)}
|
|
157
|
+
required
|
|
158
|
+
/>
|
|
159
|
+
<button
|
|
160
|
+
type="button"
|
|
161
|
+
style={toggleButtonStyle}
|
|
162
|
+
tabIndex={-1}
|
|
163
|
+
onClick={() => setShowPassword(v => !v)}
|
|
164
|
+
>
|
|
165
|
+
{showPassword ? "Hide" : "Show"}
|
|
166
|
+
</button>
|
|
167
|
+
</div>
|
|
133
168
|
<button style={buttonStyle} type="submit">Login</button>
|
|
134
169
|
</form>
|
|
135
170
|
) : (
|
|
@@ -142,28 +177,42 @@ export default function LoginRegisterFlow({ onLoginSuccess, onRegisterSuccess })
|
|
|
142
177
|
onChange={e => setIdentifier(e.target.value)}
|
|
143
178
|
required
|
|
144
179
|
/>
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
<div style={inputWrapperStyle}>
|
|
181
|
+
<input
|
|
182
|
+
style={inputStyle}
|
|
183
|
+
type={showPassword ? "text" : "password"}
|
|
184
|
+
placeholder="Password"
|
|
185
|
+
value={password}
|
|
186
|
+
onChange={e => setPassword(e.target.value)}
|
|
187
|
+
required
|
|
188
|
+
/>
|
|
189
|
+
<button
|
|
190
|
+
type="button"
|
|
191
|
+
style={toggleButtonStyle}
|
|
192
|
+
tabIndex={-1}
|
|
193
|
+
onClick={() => setShowPassword(v => !v)}
|
|
194
|
+
>
|
|
195
|
+
{showPassword ? "Hide" : "Show"}
|
|
196
|
+
</button>
|
|
197
|
+
</div>
|
|
198
|
+
<div style={inputWrapperStyle}>
|
|
199
|
+
<input
|
|
200
|
+
style={inputStyle}
|
|
201
|
+
type={showConfirmPassword ? "text" : "password"}
|
|
202
|
+
placeholder="Confirm Password"
|
|
203
|
+
value={confirmPassword}
|
|
204
|
+
onChange={e => setConfirmPassword(e.target.value)}
|
|
205
|
+
required
|
|
206
|
+
/>
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
style={toggleButtonStyle}
|
|
210
|
+
tabIndex={-1}
|
|
211
|
+
onClick={() => setShowConfirmPassword(v => !v)}
|
|
212
|
+
>
|
|
213
|
+
{showConfirmPassword ? "Hide" : "Show"}
|
|
214
|
+
</button>
|
|
215
|
+
</div>
|
|
167
216
|
<button style={buttonStyle} type="submit">Register</button>
|
|
168
217
|
</form>
|
|
169
218
|
)}
|
|
@@ -33,31 +33,32 @@ const messageStyle = (success) => ({
|
|
|
33
33
|
fontSize: 15,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
export default function LogoutButton() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
setSuccess(false);
|
|
43
|
-
const { error } = await logout();
|
|
44
|
-
if (error) {
|
|
45
|
-
setMessage(error.message || 'Logout failed');
|
|
36
|
+
export default function LogoutButton({ onLogout }) {
|
|
37
|
+
const [message, setMessage] = useState(null);
|
|
38
|
+
const [success, setSuccess] = useState(false);
|
|
39
|
+
|
|
40
|
+
const handleLogout = async () => {
|
|
41
|
+
setMessage(null);
|
|
46
42
|
setSuccess(false);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
setMessage(null);
|
|
43
|
+
const { error } = await logout();
|
|
44
|
+
if (error) {
|
|
45
|
+
setMessage(error.message || 'Logout failed');
|
|
52
46
|
setSuccess(false);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
} else {
|
|
48
|
+
setMessage('Logout successful!');
|
|
49
|
+
setSuccess(true);
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
setMessage(null);
|
|
52
|
+
setSuccess(false);
|
|
53
|
+
if (onLogout) onLogout(); // Call the callback after logout
|
|
54
|
+
}, 1500);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div style={boxStyle}>
|
|
60
|
+
<button style={buttonStyle} onClick={handleLogout}>Logout</button>
|
|
61
|
+
{message && <div style={messageStyle(success)}>{message}</div>}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|