@ebubekirylmaz/link-test 1.1.2 → 1.1.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebubekirylmaz/link-test",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "exports": {
@@ -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().required(),
16
- userPoolId: Joi.string().required(),
17
- clientId: Joi.string().required(),
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(),
@@ -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,42 @@
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
+ function handleLogin() {
13
+ if (username === "admin" && password === "admin") {
14
+ storage.set("link", "accessToken", "demo-access-token");
15
+ storage.set("link", "refreshToken", "demo-refresh-token");
16
+ navigate("/");
17
+ } else {
18
+ alert("Demo credentials are: admin / admin");
19
+ }
20
+ }
21
+
22
+ return (
23
+ <Stack spacing={2} maxWidth={400} mx="auto">
24
+ <Typography variant="h5">Demo Login</Typography>
25
+ <TextField
26
+ label="Username"
27
+ value={username}
28
+ onChange={(e) => setUsername(e.target.value)}
29
+ />
30
+ <TextField
31
+ label="Password"
32
+ type="password"
33
+ value={password}
34
+ onChange={(e) => setPassword(e.target.value)}
35
+ />
36
+ <Button variant="contained" onClick={handleLogin}>
37
+ Sign in (Demo)
38
+ </Button>
39
+ <Typography variant="caption">Use: admin / admin</Typography>
40
+ </Stack>
41
+ );
42
+ }
@@ -11,17 +11,11 @@ import { useNavigate } from "react-router-dom";
11
11
  // ----------------------------------------------------------------------
12
12
 
13
13
  export default function Auth0LoginView() {
14
- const { name, project, credentials } = config();
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