@ebubekirylmaz/link-test 1.2.40 → 1.2.41
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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import config from "../../config/config";
|
|
2
2
|
import { storage } from "@nucleoidjs/webstorage";
|
|
3
|
+
import { useNavigate } from "react-router-dom";
|
|
4
|
+
import { useSnackbar } from "notistack";
|
|
3
5
|
import { useState } from "react";
|
|
4
6
|
|
|
5
7
|
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
@@ -13,11 +15,14 @@ export default function CognitoLogin() {
|
|
|
13
15
|
const [password, setPassword] = useState("");
|
|
14
16
|
const [code, setCode] = useState("");
|
|
15
17
|
|
|
18
|
+
const navigate = useNavigate();
|
|
19
|
+
const { enqueueSnackbar } = useSnackbar();
|
|
20
|
+
|
|
16
21
|
const { appId } = config();
|
|
17
22
|
|
|
18
23
|
const handleLogin = async () => {
|
|
19
24
|
try {
|
|
20
|
-
await login(
|
|
25
|
+
await login(email, password);
|
|
21
26
|
|
|
22
27
|
const tokens = await getTokens();
|
|
23
28
|
if (!tokens?.accessToken)
|
|
@@ -42,29 +47,35 @@ export default function CognitoLogin() {
|
|
|
42
47
|
storage.set("link", "refreshToken", data.refreshToken);
|
|
43
48
|
storage.set("link", "identityProvider", "COGNITO");
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
navigate("/");
|
|
46
51
|
} catch (e) {
|
|
47
52
|
console.error("Login error:", e);
|
|
48
|
-
|
|
53
|
+
enqueueSnackbar(e.message || "Login failed", { variant: "error" });
|
|
49
54
|
}
|
|
50
55
|
};
|
|
51
56
|
|
|
52
57
|
const handleSignup = async () => {
|
|
53
58
|
try {
|
|
54
|
-
await signup(
|
|
59
|
+
await signup(email, password, password);
|
|
60
|
+
enqueueSnackbar(
|
|
61
|
+
"Account created! Please check your email for the confirmation code.",
|
|
62
|
+
{ variant: "success" }
|
|
63
|
+
);
|
|
55
64
|
setMode("confirm");
|
|
56
65
|
} catch (e) {
|
|
57
|
-
|
|
66
|
+
enqueueSnackbar(e.message || "Signup failed", { variant: "error" });
|
|
58
67
|
}
|
|
59
68
|
};
|
|
60
69
|
|
|
61
70
|
const handleConfirm = async () => {
|
|
62
71
|
try {
|
|
63
|
-
await confirmSignup(
|
|
64
|
-
|
|
72
|
+
await confirmSignup(email, code);
|
|
73
|
+
enqueueSnackbar("Account confirmed! You can now log in.", {
|
|
74
|
+
variant: "success",
|
|
75
|
+
});
|
|
65
76
|
setMode("login");
|
|
66
77
|
} catch (e) {
|
|
67
|
-
|
|
78
|
+
enqueueSnackbar(e.message || "Confirmation failed", { variant: "error" });
|
|
68
79
|
}
|
|
69
80
|
};
|
|
70
81
|
|
|
@@ -78,9 +89,9 @@ export default function CognitoLogin() {
|
|
|
78
89
|
|
|
79
90
|
<Stack spacing={2}>
|
|
80
91
|
<TextField
|
|
81
|
-
label="
|
|
82
|
-
value={
|
|
83
|
-
onChange={(e) =>
|
|
92
|
+
label="Email"
|
|
93
|
+
value={email}
|
|
94
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
84
95
|
/>
|
|
85
96
|
|
|
86
97
|
{mode === "signup" && (
|