@ebubekirylmaz/link-test 1.2.23 → 1.2.25
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 +1 -1
- package/src/Platform.jsx +3 -0
- package/src/pages/LoginPage.jsx +1 -2
- package/src/widgets/Login/CognitoLogin.jsx +4 -3
- package/src/widgets/Login/amplifyAuth.js +14 -23
- package/src/widgets/Login/amplifyConfig.js +20 -0
- package/src/widgets/Login/AmplifyLogin.jsx +0 -54
- package/src/widgets/Login/amplify.jsx +0 -30
package/package.json
CHANGED
package/src/Platform.jsx
CHANGED
|
@@ -14,10 +14,13 @@ import { SettingsProvider } from "./components/settings";
|
|
|
14
14
|
import { SnackbarProvider } from "notistack";
|
|
15
15
|
import ThemeProvider from "./theme";
|
|
16
16
|
import config from "./config/config";
|
|
17
|
+
import { configureAmplify } from "./widgets/Login/amplifyConfig";
|
|
17
18
|
import http from "./http";
|
|
18
19
|
import { init } from "./config/config";
|
|
19
20
|
import oauth from "./http/oauth";
|
|
20
21
|
|
|
22
|
+
configureAmplify();
|
|
23
|
+
|
|
21
24
|
init();
|
|
22
25
|
|
|
23
26
|
window["@nucleoidai"] = {
|
package/src/pages/LoginPage.jsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import AmplifyLogin from "../widgets/Login/AmplifyLogin";
|
|
2
1
|
import CognitoLogin from "../widgets/Login/CognitoLogin";
|
|
3
2
|
import DemoLogin from "../widgets/Login/DemoLogin";
|
|
4
3
|
import LoginForm from "../widgets/LoginForm/LoginForm";
|
|
@@ -32,7 +31,7 @@ function LoginPage() {
|
|
|
32
31
|
}, [navigate]);
|
|
33
32
|
|
|
34
33
|
if (credentials?.provider === "COGNITO") {
|
|
35
|
-
return <
|
|
34
|
+
return <CognitoLogin />;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
if (credentials?.provider === "DEMO") {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
2
|
+
|
|
3
|
+
import { login } from "./amplifyAuth";
|
|
1
4
|
import { loginWithCognito } from "./cognitoAuth";
|
|
2
5
|
import { storage } from "@nucleoidjs/webstorage";
|
|
3
6
|
import { useState } from "react";
|
|
4
7
|
|
|
5
|
-
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
6
|
-
|
|
7
8
|
export default function CognitoLogin() {
|
|
8
9
|
const [username, setUsername] = useState("");
|
|
9
10
|
const [password, setPassword] = useState("");
|
|
10
11
|
|
|
11
12
|
const handleLogin = async () => {
|
|
12
13
|
try {
|
|
13
|
-
const tokens = await
|
|
14
|
+
const tokens = await login(username, password);
|
|
14
15
|
console.log("Login successful, tokens:", tokens);
|
|
15
16
|
storage.set("link", "accessToken", tokens.AccessToken);
|
|
16
17
|
storage.set("link", "refreshToken", tokens.RefreshToken);
|
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import config from "../../config/config";
|
|
1
|
+
import { fetchAuthSession, signIn, signOut } from "aws-amplify/auth";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (initialized) return;
|
|
3
|
+
export async function login(username, password) {
|
|
4
|
+
return signIn({ username, password });
|
|
5
|
+
}
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
7
|
+
export async function logout() {
|
|
8
|
+
await signOut();
|
|
9
|
+
}
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
region: credentials.region,
|
|
18
|
-
userPoolId: credentials.userPoolId,
|
|
19
|
-
userPoolWebClientId: credentials.clientId,
|
|
20
|
-
authenticationFlowType: "USER_SRP_AUTH",
|
|
21
|
-
oauth: undefined, // disable Hosted UI
|
|
22
|
-
},
|
|
23
|
-
});
|
|
11
|
+
export async function getTokens() {
|
|
12
|
+
const session = await fetchAuthSession();
|
|
24
13
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
return {
|
|
15
|
+
accessToken: session.tokens?.accessToken?.toString(),
|
|
16
|
+
refreshToken: session.tokens?.refreshToken?.toString(),
|
|
17
|
+
idToken: session.tokens?.idToken?.toString(),
|
|
18
|
+
};
|
|
28
19
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Amplify } from "aws-amplify";
|
|
2
|
+
import config from "../../config/config";
|
|
3
|
+
|
|
4
|
+
export function configureAmplify() {
|
|
5
|
+
const { credentials } = config();
|
|
6
|
+
|
|
7
|
+
if (!credentials) {
|
|
8
|
+
throw new Error("CONFIG not initialized yet");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Amplify.configure({
|
|
12
|
+
Auth: {
|
|
13
|
+
Cognito: {
|
|
14
|
+
userPoolId: credentials.userPoolId,
|
|
15
|
+
userPoolClientId: credentials.clientId,
|
|
16
|
+
region: credentials.region,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
2
|
-
|
|
3
|
-
import { loginWithAmplify } from "./amplify";
|
|
4
|
-
import { storage } from "@nucleoidjs/webstorage";
|
|
5
|
-
import { useState } from "react";
|
|
6
|
-
|
|
7
|
-
export default function AmplifyLogin() {
|
|
8
|
-
const [username, setUsername] = useState("");
|
|
9
|
-
const [password, setPassword] = useState("");
|
|
10
|
-
|
|
11
|
-
const handleLogin = async () => {
|
|
12
|
-
try {
|
|
13
|
-
const result = await loginWithAmplify(username, password);
|
|
14
|
-
|
|
15
|
-
if (result.challenge) {
|
|
16
|
-
console.log("Challenge required:", result.challenge);
|
|
17
|
-
alert(`Challenge required: ${result.challenge}`);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
console.log("Login successful, tokens:", result);
|
|
22
|
-
|
|
23
|
-
storage.set("link", "accessToken", result.AccessToken);
|
|
24
|
-
storage.set("link", "refreshToken", result.RefreshToken);
|
|
25
|
-
|
|
26
|
-
window.location.href = "/";
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.error("Login error:", e);
|
|
29
|
-
alert(`Login failed: ${e.message || e}`);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<>
|
|
35
|
-
<Typography variant="h4">Login</Typography>
|
|
36
|
-
<Stack spacing={2}>
|
|
37
|
-
<TextField
|
|
38
|
-
label="Username or Email"
|
|
39
|
-
value={username}
|
|
40
|
-
onChange={(e) => setUsername(e.target.value)}
|
|
41
|
-
/>
|
|
42
|
-
<TextField
|
|
43
|
-
type="password"
|
|
44
|
-
label="Password"
|
|
45
|
-
value={password}
|
|
46
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
47
|
-
/>
|
|
48
|
-
<Button variant="contained" onClick={handleLogin}>
|
|
49
|
-
Login
|
|
50
|
-
</Button>
|
|
51
|
-
</Stack>
|
|
52
|
-
</>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { fetchAuthSession, signIn } from "aws-amplify/auth";
|
|
2
|
-
|
|
3
|
-
import { ensureAmplifyAuth } from "./amplifyAuth";
|
|
4
|
-
|
|
5
|
-
export async function loginWithAmplify(username, password) {
|
|
6
|
-
const ready = ensureAmplifyAuth();
|
|
7
|
-
if (!ready) {
|
|
8
|
-
throw new Error("Auth not ready yet. Please try again.");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const result = await signIn({
|
|
12
|
-
username,
|
|
13
|
-
password,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
if (result.nextStep?.signInStep !== "DONE") {
|
|
17
|
-
return {
|
|
18
|
-
challenge: result.nextStep.signInStep,
|
|
19
|
-
result,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const session = await fetchAuthSession();
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
AccessToken: session.tokens?.accessToken?.toString(),
|
|
27
|
-
IdToken: session.tokens?.idToken?.toString(),
|
|
28
|
-
RefreshToken: session.tokens?.refreshToken?.toString(),
|
|
29
|
-
};
|
|
30
|
-
}
|