@ebubekirylmaz/link-test 1.1.0 → 1.1.2

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.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "exports": {
@@ -11,11 +11,17 @@ import { useNavigate } from "react-router-dom";
11
11
  // ----------------------------------------------------------------------
12
12
 
13
13
  export default function Auth0LoginView() {
14
- const { name, project } = config();
14
+ const { name, project, credentials } = 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
+
19
25
  const navigate = useNavigate();
20
26
 
21
27
  function token() {
@@ -33,6 +39,11 @@ export default function Auth0LoginView() {
33
39
  if (token()) {
34
40
  navigate("/");
35
41
  }
42
+
43
+ if (credentials?.provider === "DEMO") {
44
+ signInAsDemo();
45
+ navigate("/");
46
+ }
36
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
37
48
  }, [navigate]);
38
49
 
@@ -5,25 +5,40 @@ import {
5
5
  InitiateAuthCommand,
6
6
  } from "@aws-sdk/client-cognito-identity-provider";
7
7
 
8
- const { credentials } = config();
8
+ let client = null;
9
9
 
10
- const client = new CognitoIdentityProviderClient({
11
- region: credentials?.region,
12
- });
10
+ function getClient() {
11
+ if (!client) {
12
+ const { credentials } = config();
13
+ if (!credentials) {
14
+ throw new Error("Cognito credentials not initialized yet");
15
+ }
13
16
 
14
- console.log("Initialized Cognito Client with region:", credentials?.region);
15
- console.log("credentials", credentials?.clientId);
17
+ client = new CognitoIdentityProviderClient({
18
+ region: credentials.region,
19
+ });
20
+
21
+ console.log("Initialized Cognito Client with region:", credentials.region);
22
+ }
23
+
24
+ return client;
25
+ }
16
26
 
17
27
  export async function loginWithCognito(username, password) {
28
+ const { credentials } = config();
29
+ if (!credentials) {
30
+ throw new Error("CONFIG not initialized yet. Wait for CONFIG_INITIALIZED.");
31
+ }
32
+
18
33
  const command = new InitiateAuthCommand({
19
34
  AuthFlow: "USER_PASSWORD_AUTH",
20
- ClientId: credentials?.clientId,
35
+ ClientId: credentials.clientId,
21
36
  AuthParameters: {
22
37
  USERNAME: username,
23
38
  PASSWORD: password,
24
39
  },
25
40
  });
26
41
 
27
- const response = await client.send(command);
42
+ const response = await getClient().send(command);
28
43
  return response.AuthenticationResult;
29
44
  }