@ebubekirylmaz/link-test 1.2.34 → 1.2.36

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.2.34",
3
+ "version": "1.2.36",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -91,18 +91,22 @@ function ProjectBar() {
91
91
  const handleSelect = (project) => {
92
92
  const { id: projectId } = project;
93
93
 
94
- const refreshToken = storage.get("link", "refreshToken");
95
- const identityProvider = storage.get("link", "identityProvider");
94
+ const identityProviderRaw = storage.get("link", "identityProvider");
95
+ const identityProvider = identityProviderRaw?.toUpperCase();
96
96
 
97
97
  const payload = {
98
98
  appId,
99
99
  projectId,
100
100
  identityProvider,
101
- refreshToken,
102
101
  };
103
- if (identityProvider?.toUpperCase() === "DEMO") {
102
+
103
+ if (identityProvider === "DEMO") {
104
104
  payload.username = "admin";
105
105
  payload.password = "admin";
106
+ } else if (identityProvider === "COGNITO") {
107
+ payload.refreshToken = storage.get("link", "cognitoAccessToken");
108
+ } else {
109
+ payload.refreshToken = storage.get("link", "refreshToken");
106
110
  }
107
111
 
108
112
  const request = oauth.post("/oauth", payload);
@@ -17,34 +17,34 @@ export default function CognitoLogin() {
17
17
 
18
18
  const handleLogin = async () => {
19
19
  try {
20
- // 1️⃣ Login with Cognito
20
+ // 1) Cognito sign-in (SRP handled by Amplify)
21
21
  await login(username, password);
22
22
 
23
- // 2️⃣ Get Cognito tokens
23
+ // 2) Get Cognito tokens
24
24
  const tokens = await getTokens();
25
-
26
- if (!tokens?.accessToken) {
25
+ if (!tokens?.accessToken)
27
26
  throw new Error("No Cognito access token received");
28
- }
29
27
 
28
+ // ✅ Store Cognito access token separately (external token)
29
+ storage.set("link", "cognitoAccessToken", tokens.accessToken);
30
+
31
+ // 3) Exchange Cognito token with YOUR backend
30
32
  const res = await fetch("/api/oauth", {
31
33
  method: "POST",
32
34
  headers: { "Content-Type": "application/json" },
33
35
  body: JSON.stringify({
34
- appId: appId,
36
+ appId,
35
37
  projectId: "cb16e069-6214-47f1-9922-1f7fe7629525",
36
38
  identityProvider: "COGNITO",
37
- refreshToken: tokens.accessToken, // 🔥 Cognito ACCESS token
39
+ refreshToken: tokens.accessToken, // <-- external Cognito access token (JWT with kid)
38
40
  }),
39
41
  });
40
42
 
41
- if (!res.ok) {
42
- throw new Error("Backend OAuth exchange failed");
43
- }
43
+ if (!res.ok) throw new Error("Backend OAuth exchange failed");
44
44
 
45
45
  const data = await res.json();
46
46
 
47
- // 4️⃣ Store INTERNAL tokens (same as Demo)
47
+ // 4) Store INTERNAL tokens (issued by your backend)
48
48
  storage.set("link", "accessToken", data.accessToken);
49
49
  storage.set("link", "refreshToken", data.refreshToken);
50
50
  storage.set("link", "identityProvider", "COGNITO");