Skip to content

Commit 6cdc8fe

Browse files
committed
fix(fix deps and clientkey): fix client key and deps
1 parent a6809f7 commit 6cdc8fe

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
]
113113
},
114114
"dependencies": {
115-
"@trycourier/courier-js": "^1.4.2",
116115
"pkg-dir": "^7.0.0"
117116
}
118117
}

packages/react-provider/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"license": "ISC",
1818
"dependencies": {
19+
"@trycourier/courier-js": "^1.4.2",
1920
"@trycourier/client-graphql": "^6.0.0",
2021
"buffer": "^6.0.3",
2122
"jwt-decode": "^3.1.2",

packages/react-provider/src/hooks/use-courier-actions.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@trycourier/client-graphql";
88
import { Brand, CourierTransport } from "..";
99
import courier from "@trycourier/courier-js";
10+
import jwtDecode from "jwt-decode";
1011

1112
import { ICourierContext } from "~/types";
1213

@@ -21,10 +22,28 @@ const useCourierActions = (state, dispatch): ICourierContext => {
2122
userSignature: state.userSignature,
2223
});
2324

25+
let clientKey = state.clientKey;
26+
27+
//ensure we always have a clientkey
28+
if (!clientKey && state.authorization) {
29+
const decoded = jwtDecode(state.authorization) as {
30+
tenant_scope: string;
31+
tenant_id: string;
32+
scope: string;
33+
};
34+
35+
let tenantId = decoded.tenant_id;
36+
if (decoded.tenant_scope.includes("test")) {
37+
tenantId = `${tenantId}/test`;
38+
}
39+
40+
clientKey = btoa(tenantId);
41+
}
42+
2443
courier.init({
2544
baseUrl: state.apiUrl,
2645
authorization: state.authorization,
27-
clientKey: state.clientKey,
46+
clientKey,
2847
userId: state.userId,
2948
userSignature: state.userSignature,
3049
});

0 commit comments

Comments
 (0)