@ebubekirylmaz/link-test 1.1.2 → 1.1.4
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
package/src/config/schemas.js
CHANGED
|
@@ -12,9 +12,9 @@ export const ConfigSchema = Joi.object({
|
|
|
12
12
|
}).optional(),
|
|
13
13
|
credentials: Joi.object({
|
|
14
14
|
provider: Joi.string().valid("DEMO", "COGNITO").required(),
|
|
15
|
-
region: Joi.string().
|
|
16
|
-
userPoolId: Joi.string().
|
|
17
|
-
clientId: Joi.string().
|
|
15
|
+
region: Joi.string().optional(),
|
|
16
|
+
userPoolId: Joi.string().optional(),
|
|
17
|
+
clientId: Joi.string().optional(),
|
|
18
18
|
}).optional(),
|
|
19
19
|
project: Joi.object({
|
|
20
20
|
nucleoid: Joi.object().optional(),
|
package/src/pages/LoginPage.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CognitoLogin from "../widgets/Login/CognitoLogin";
|
|
2
|
+
import DemoLogin from "../widgets/Login/DemoLogin";
|
|
2
3
|
import LoginForm from "../widgets/LoginForm/LoginForm";
|
|
3
4
|
import Page from "../layouts/Page";
|
|
4
5
|
import React from "react";
|
|
@@ -33,6 +34,14 @@ function LoginPage() {
|
|
|
33
34
|
return <CognitoLogin />;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
if (credentials?.provider === "DEMO") {
|
|
38
|
+
return (
|
|
39
|
+
<Page title={`Sign in to ${name}`}>
|
|
40
|
+
<DemoLogin />
|
|
41
|
+
</Page>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
return (
|
|
37
46
|
<Page title={`Sign in to ${name}`}>
|
|
38
47
|
<LoginForm icon={template.login.icon} name={name} formColor={formColor} />
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { storage } from "@nucleoidjs/webstorage";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
import { Button, Stack, TextField, Typography } from "@mui/material";
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
|
|
7
|
+
export default function DemoLogin() {
|
|
8
|
+
const [username, setUsername] = useState("");
|
|
9
|
+
const [password, setPassword] = useState("");
|
|
10
|
+
const navigate = useNavigate();
|
|
11
|
+
|
|
12
|
+
async function handleLogin() {
|
|
13
|
+
const res = await fetch("/auth/demo", {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: { "Content-Type": "application/json" },
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
appId,
|
|
18
|
+
projectId,
|
|
19
|
+
username,
|
|
20
|
+
password,
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!res.ok) throw new Error("Demo login failed");
|
|
25
|
+
|
|
26
|
+
const data = await res.json();
|
|
27
|
+
|
|
28
|
+
storage.set("link", "accessToken", data.accessToken);
|
|
29
|
+
storage.set("link", "refreshToken", data.refreshToken);
|
|
30
|
+
|
|
31
|
+
navigate("/");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Stack spacing={2} maxWidth={400} mx="auto">
|
|
36
|
+
<Typography variant="h5">Demo Login</Typography>
|
|
37
|
+
<TextField
|
|
38
|
+
label="Username"
|
|
39
|
+
value={username}
|
|
40
|
+
onChange={(e) => setUsername(e.target.value)}
|
|
41
|
+
/>
|
|
42
|
+
<TextField
|
|
43
|
+
label="Password"
|
|
44
|
+
type="password"
|
|
45
|
+
value={password}
|
|
46
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
47
|
+
/>
|
|
48
|
+
<Button variant="contained" onClick={handleLogin}>
|
|
49
|
+
Sign in (Demo)
|
|
50
|
+
</Button>
|
|
51
|
+
<Typography variant="caption">Use: admin / admin</Typography>
|
|
52
|
+
</Stack>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -11,17 +11,11 @@ import { useNavigate } from "react-router-dom";
|
|
|
11
11
|
// ----------------------------------------------------------------------
|
|
12
12
|
|
|
13
13
|
export default function Auth0LoginView() {
|
|
14
|
-
const { name, project
|
|
14
|
+
const { name, project } = config();
|
|
15
15
|
|
|
16
16
|
const handleOAuthLogin = ({ authUrl, clientId, redirectUri, scope }) => {
|
|
17
17
|
window.location.href = `${authUrl}?client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code`;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
function signInAsDemo() {
|
|
21
|
-
storage.set("link", "accessToken", "demo-access-token");
|
|
22
|
-
storage.set("link", "refreshToken", "demo-refresh-token");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
19
|
const navigate = useNavigate();
|
|
26
20
|
|
|
27
21
|
function token() {
|
|
@@ -39,11 +33,6 @@ export default function Auth0LoginView() {
|
|
|
39
33
|
if (token()) {
|
|
40
34
|
navigate("/");
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
if (credentials?.provider === "DEMO") {
|
|
44
|
-
signInAsDemo();
|
|
45
|
-
navigate("/");
|
|
46
|
-
}
|
|
47
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
37
|
}, [navigate]);
|
|
49
38
|
|