Skip to content

Commit e206a68

Browse files
committed
refactor: use passed tokens in activity timeout instead of fetching from storage
1 parent 6e5690c commit e206a68

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
],
103103
"private": false,
104104
"dependencies": {
105-
"@kinde/js-utils": "0.27.0"
105+
"@kinde/js-utils": "0.29.0"
106106
},
107107
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
108108
}

src/state/KindeProvider.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
setActiveStorage,
3232
isAuthenticated,
3333
updateActivityTimestamp,
34-
getInsecureStorage,
3534
} from "@kinde/js-utils";
3635
import * as storeState from "./store";
3736
import React, {
@@ -55,6 +54,7 @@ import type {
5554
RefreshTokenResult,
5655
Scopes,
5756
SessionManager,
57+
TimeoutTokenData,
5858
} from "@kinde/js-utils";
5959
// TODO: need to look for old token store and convert.
6060
storageSettings.keyPrefix = "";
@@ -229,39 +229,38 @@ export const KindeProvider = ({
229229
storageSettings.activityTimeoutMinutes = activityTimeout.timeoutMinutes;
230230
storageSettings.activityTimeoutPreWarningMinutes =
231231
activityTimeout.preWarningMinutes;
232-
storageSettings.onActivityTimeout = async (type: TimeoutActivityType) => {
232+
storageSettings.onActivityTimeout = async (
233+
type: TimeoutActivityType,
234+
tokens?: TimeoutTokenData,
235+
) => {
233236
try {
234237
if (type === TimeoutActivityType.timeout) {
235-
const insecureStorage = getInsecureStorage();
236-
const accessToken = await store.getSessionItem(
237-
StorageKeys.accessToken,
238-
);
239-
const refreshToken = await insecureStorage?.getSessionItem(
240-
StorageKeys.refreshToken,
241-
);
238+
const accessToken = tokens?.accessToken;
239+
const refreshToken = tokens?.refreshToken;
240+
242241
await Promise.all([
243242
await fetch(`${domain}/logout`),
244243
refreshToken &&
245244
(await fetch(`${domain}/oauth2/revoke`, {
246245
method: "POST",
247246
body: JSON.stringify({
248-
token: await store.getSessionItem(StorageKeys.accessToken),
247+
token: refreshToken,
249248
}),
250249
headers: {
251250
"Content-Type": "application/json",
252-
Authorization: `Bearer ${await store.getSessionItem(StorageKeys.accessToken)}`,
251+
Authorization: `Bearer ${accessToken}`,
253252
},
254253
})),
255254
]);
256255
if (accessToken) {
257256
await fetch(`${domain}/oauth2/revoke`, {
258257
method: "POST",
259258
body: JSON.stringify({
260-
token: await store.getSessionItem(StorageKeys.accessToken),
259+
token: accessToken,
261260
}),
262261
headers: {
263262
"Content-Type": "application/json",
264-
Authorization: `Bearer ${await store.getSessionItem(StorageKeys.accessToken)}`,
263+
Authorization: `Bearer ${accessToken}`,
265264
},
266265
});
267266
}

0 commit comments

Comments
 (0)