@ebubekirylmaz/link-test 1.2.26 → 1.2.28
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,45 +1,108 @@
|
|
|
1
1
|
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
2
|
+
import { confirmSignup, login, signup } from "./amplifyAuth";
|
|
2
3
|
|
|
3
|
-
import { login } from "./amplifyAuth";
|
|
4
|
-
import { loginWithCognito } from "./cognitoAuth";
|
|
5
4
|
import { storage } from "@nucleoidjs/webstorage";
|
|
6
5
|
import { useState } from "react";
|
|
7
6
|
|
|
8
7
|
export default function CognitoLogin() {
|
|
8
|
+
const [mode, setMode] = useState("login");
|
|
9
|
+
|
|
9
10
|
const [username, setUsername] = useState("");
|
|
11
|
+
const [email, setEmail] = useState("");
|
|
10
12
|
const [password, setPassword] = useState("");
|
|
13
|
+
const [code, setCode] = useState("");
|
|
11
14
|
|
|
12
15
|
const handleLogin = async () => {
|
|
13
16
|
try {
|
|
14
|
-
|
|
15
|
-
console.log("Login successful, tokens:", tokens);
|
|
16
|
-
storage.set("link", "accessToken", tokens.AccessToken);
|
|
17
|
-
storage.set("link", "refreshToken", tokens.RefreshToken);
|
|
17
|
+
await login(username, password);
|
|
18
18
|
window.location.href = "/";
|
|
19
19
|
} catch (e) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
alert(e.message || "Login failed");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const handleSignup = async () => {
|
|
25
|
+
try {
|
|
26
|
+
await signup(username, password, email);
|
|
27
|
+
setMode("confirm");
|
|
28
|
+
} catch (e) {
|
|
29
|
+
alert(e.message || "Signup failed");
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const handleConfirm = async () => {
|
|
34
|
+
try {
|
|
35
|
+
await confirmSignup(username, code);
|
|
36
|
+
alert("Account confirmed! You can now log in.");
|
|
37
|
+
setMode("login");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
alert(e.message || "Confirmation failed");
|
|
22
40
|
}
|
|
23
41
|
};
|
|
24
42
|
|
|
25
43
|
return (
|
|
26
44
|
<>
|
|
27
|
-
<Typography variant="h4">
|
|
45
|
+
<Typography variant="h4" gutterBottom>
|
|
46
|
+
{mode === "login" && "Login"}
|
|
47
|
+
{mode === "signup" && "Sign Up"}
|
|
48
|
+
{mode === "confirm" && "Confirm Account"}
|
|
49
|
+
</Typography>
|
|
50
|
+
|
|
28
51
|
<Stack spacing={2}>
|
|
29
52
|
<TextField
|
|
30
53
|
label="Username or Email"
|
|
31
54
|
value={username}
|
|
32
55
|
onChange={(e) => setUsername(e.target.value)}
|
|
33
56
|
/>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
|
|
58
|
+
{mode === "signup" && (
|
|
59
|
+
<TextField
|
|
60
|
+
label="Email"
|
|
61
|
+
value={email}
|
|
62
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
|
|
66
|
+
{mode !== "confirm" && (
|
|
67
|
+
<TextField
|
|
68
|
+
type="password"
|
|
69
|
+
label="Password"
|
|
70
|
+
value={password}
|
|
71
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
|
|
75
|
+
{mode === "confirm" && (
|
|
76
|
+
<TextField
|
|
77
|
+
label="Confirmation Code"
|
|
78
|
+
value={code}
|
|
79
|
+
onChange={(e) => setCode(e.target.value)}
|
|
80
|
+
/>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{mode === "login" && (
|
|
84
|
+
<>
|
|
85
|
+
<Button variant="contained" onClick={handleLogin}>
|
|
86
|
+
Login
|
|
87
|
+
</Button>
|
|
88
|
+
<Button onClick={() => setMode("signup")}>Create an account</Button>
|
|
89
|
+
</>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
{mode === "signup" && (
|
|
93
|
+
<>
|
|
94
|
+
<Button variant="contained" onClick={handleSignup}>
|
|
95
|
+
Sign Up
|
|
96
|
+
</Button>
|
|
97
|
+
<Button onClick={() => setMode("login")}>Back to login</Button>
|
|
98
|
+
</>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
{mode === "confirm" && (
|
|
102
|
+
<Button variant="contained" onClick={handleConfirm}>
|
|
103
|
+
Confirm
|
|
104
|
+
</Button>
|
|
105
|
+
)}
|
|
43
106
|
</Stack>
|
|
44
107
|
</>
|
|
45
108
|
);
|
|
@@ -1,9 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
confirmSignUp,
|
|
3
|
+
fetchAuthSession,
|
|
4
|
+
signIn,
|
|
5
|
+
signOut,
|
|
6
|
+
signUp,
|
|
7
|
+
} from "aws-amplify/auth";
|
|
2
8
|
|
|
3
9
|
export async function login(username, password) {
|
|
4
10
|
return signIn({ username, password });
|
|
5
11
|
}
|
|
6
12
|
|
|
13
|
+
export async function signup(username, password, email) {
|
|
14
|
+
return signUp({
|
|
15
|
+
username,
|
|
16
|
+
password,
|
|
17
|
+
options: {
|
|
18
|
+
userAttributes: {
|
|
19
|
+
email,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function confirmSignup(username, code) {
|
|
26
|
+
return confirmSignUp({
|
|
27
|
+
username,
|
|
28
|
+
confirmationCode: code,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
7
32
|
export async function logout() {
|
|
8
33
|
await signOut();
|
|
9
34
|
}
|