Skip to content

Commit 02e2135

Browse files
committed
fix: get token properly in auth api client
1 parent ab1adb7 commit 02e2135

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kodado/kodado-js",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"browser": "dist/index.js",
55
"main": "dist_node/index.js",
66
"types": "dist/index.d.ts",

src/auth/AuthApiClient.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,36 @@ export class AuthApiClient {
4444
fullName,
4545
companyName,
4646
emailNotifications,
47+
token,
4748
}: {
4849
fullName?: string;
4950
companyName?: string;
5051
emailNotifications?: string;
52+
token: string;
5153
}) {
5254
await fetch(`${this.endpoint}/auth/profile`, {
5355
method: "PUT",
5456
body: JSON.stringify({ fullName, companyName, emailNotifications }),
5557
headers: {
56-
Authorization: this.session?.getIdToken().getJwtToken() || "",
58+
Authorization: token,
5759
},
5860
});
5961
}
6062

61-
async deleteUserProfile() {
63+
async deleteUserProfile(token: string) {
6264
await fetch(`${this.endpoint}/auth`, {
6365
method: "DELETE",
6466
headers: {
65-
Authorization: this.session?.getIdToken().getJwtToken() || "",
67+
Authorization: token,
6668
},
6769
});
6870
}
6971

70-
async uploadUserProfileImage(image: any) {
72+
async uploadUserProfileImage(image: any, token: string) {
7173
const response = await fetch(`${this.endpoint}/auth/profile/image`, {
7274
method: "POST",
7375
headers: {
74-
Authorization: this.session?.getIdToken().getJwtToken() || "",
76+
Authorization: token,
7577
},
7678
});
7779

@@ -85,7 +87,7 @@ export class AuthApiClient {
8587
return data;
8688
}
8789

88-
async getUserKeys() {
90+
async getUserKeys(token: string) {
8991
const response = await fetch(`${this.endpoint}/keys/user`, {
9092
method: "POST",
9193
headers: {
@@ -101,7 +103,7 @@ export class AuthApiClient {
101103
const response = await fetch(`${this.endpoint}/keys/user`, {
102104
method: "POST",
103105
headers: {
104-
Authorization: this.session?.getIdToken().getJwtToken() || "",
106+
Authorization: token,
105107
},
106108
body: JSON.stringify({ page: index + 2 }),
107109
});
@@ -118,12 +120,16 @@ export class AuthApiClient {
118120
return keys;
119121
}
120122

121-
async updateItemKeys(encryptionPublicKey: string, encryptedItemKeys: any) {
123+
async updateItemKeys(
124+
encryptionPublicKey: string,
125+
encryptedItemKeys: any,
126+
token: string
127+
) {
122128
await fetch(`${this.endpoint}/auth/password`, {
123129
method: "POST",
124130

125131
headers: {
126-
Authorization: this.session?.getIdToken().getJwtToken() || "",
132+
Authorization: token,
127133
},
128134
body: JSON.stringify({
129135
encryptionPublicKey,

src/auth/AuthClient.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export class AuthClient {
257257
fullName,
258258
companyName,
259259
emailNotifications: JSON.stringify(emailNotifications),
260+
token: (await this.getCurrentAuthorizationToken()) || "",
260261
});
261262
await this.cognitoClient.updateCognitoProfile(this.session, {
262263
fullName,
@@ -271,7 +272,10 @@ export class AuthClient {
271272
}
272273

273274
async uploadProfileImage(image: any) {
274-
await this.apiClient.uploadUserProfileImage(image);
275+
await this.apiClient.uploadUserProfileImage(
276+
image,
277+
(await this.getCurrentAuthorizationToken()) || ""
278+
);
275279
}
276280

277281
signOut() {
@@ -298,7 +302,9 @@ export class AuthClient {
298302

299303
user.setSignInUserSession(this.session);
300304

301-
await this.apiClient.deleteUserProfile();
305+
await this.apiClient.deleteUserProfile(
306+
(await this.getCurrentAuthorizationToken()) || ""
307+
);
302308

303309
this.user = null;
304310
this.session = null;
@@ -342,7 +348,9 @@ export class AuthClient {
342348
newPassword,
343349
});
344350

345-
const keys = await this.apiClient.getUserKeys();
351+
const keys = await this.apiClient.getUserKeys(
352+
(await this.getCurrentAuthorizationToken()) || ""
353+
);
346354

347355
const decryptedItemKeys = keys.map((key: any) => ({
348356
...key,
@@ -388,7 +396,8 @@ export class AuthClient {
388396

389397
await this.apiClient.updateItemKeys(
390398
encodeBase64(newKeys.encryptionPublicKey),
391-
encryptedItemKeys
399+
encryptedItemKeys,
400+
(await this.getCurrentAuthorizationToken()) || ""
392401
);
393402

394403
if (this.keys) {

0 commit comments

Comments
 (0)