Skip to content

Commit fc148f9

Browse files
authored
Merge branch 'main' into main
2 parents 5acbd4f + 7a489a5 commit fc148f9

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [5.9.0](https://github.com/kinde-oss/kinde-auth-react/compare/5.8.0...5.9.0)
8+
9+
- feat: make browser tab focus refresh optional [`#190`](https://github.com/kinde-oss/kinde-auth-react/pull/190)
10+
711
#### [5.8.0](https://github.com/kinde-oss/kinde-auth-react/compare/5.7.2...5.8.0)
812

13+
> 9 October 2025
14+
915
- feat: add store subscription [`#187`](https://github.com/kinde-oss/kinde-auth-react/pull/187)
16+
- chore: release v5.8.0 [`3b8cad1`](https://github.com/kinde-oss/kinde-auth-react/commit/3b8cad14a892714683ff5b7d5b52eec966e53dd2)
1017
- chore: lock file maintainance [`aec0c5f`](https://github.com/kinde-oss/kinde-auth-react/commit/aec0c5ff40ebc43511d5e005bf48960278dfbd77)
1118
- Update CODEOWNERS [`8ee1063`](https://github.com/kinde-oss/kinde-auth-react/commit/8ee1063a8e818c27f72677811e80a3553bded367)
12-
- Update CODEOWNERS [`caf105f`](https://github.com/kinde-oss/kinde-auth-react/commit/caf105fe3a6c56f919373064cce4e0e344bdd989)
1319

1420
#### [5.7.2](https://github.com/kinde-oss/kinde-auth-react/compare/5.7.1...5.7.2)
1521

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinde-oss/kinde-auth-react",
3-
"version": "5.8.0",
3+
"version": "5.9.0",
44
"description": "Kinde React SDK for authentication",
55
"module": "./dist/index.mjs",
66
"main": "./dist/index.cjs",

src/state/KindeProvider.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type KindeProviderProps = {
122122
* ⚠️ Must be memoized or defined outside component to prevent effect re-runs.
123123
*/
124124
activityTimeout?: ActivityTimeoutConfig;
125+
refreshOnFocus?: boolean
125126
};
126127

127128
const defaultCallbacks: KindeCallbacks = {
@@ -158,6 +159,7 @@ export const KindeProvider = ({
158159
popupOptions = {},
159160
store = storeState.memoryStorage,
160161
activityTimeout,
162+
refreshOnFocus = false,
161163
}: KindeProviderProps) => {
162164
const mergedCallbacks = { ...defaultCallbacks, ...callbacks };
163165

@@ -605,32 +607,35 @@ export const KindeProvider = ({
605607
);
606608

607609
const handleFocus = useCallback(() => {
608-
if (document.visibilityState === "visible" && state.isAuthenticated) {
610+
if (document.visibilityState === "visible" && state.isAuthenticated && refreshOnFocus) {
609611
refreshToken({ domain, clientId, onRefresh }).catch((error) => {
610612
console.error("Error refreshing token:", error);
611613
});
612614
}
613-
}, [state.isAuthenticated, domain, clientId, onRefresh]);
615+
}, [state.isAuthenticated, domain, clientId, onRefresh, refreshOnFocus]);
614616

615617
useEffect(() => {
616618
// remove any existing event listener before adding a new one
619+
617620
document.removeEventListener("visibilitychange", handleFocus);
621+
if (refreshOnFocus) {
618622
document.addEventListener("visibilitychange", handleFocus);
619-
return () => {
620-
document.removeEventListener("visibilitychange", handleFocus);
621-
};
622-
}, [handleFocus]);
623+
return () => {
624+
document.removeEventListener("visibilitychange", handleFocus);
625+
};
626+
}
627+
}, [handleFocus, refreshOnFocus]);
623628

624629
const init = useCallback(async () => {
625630
if (initRef.current) return;
626631
try {
627632
try {
633+
initRef.current = true;
628634
await checkAuth({ domain, clientId });
629635
} catch (err) {
630636
console.warn("checkAuth failed:", err);
631637
setState((v: ProviderState) => ({ ...v, isLoading: false }));
632638
}
633-
initRef.current = true;
634639
const params = new URLSearchParams(window.location.search);
635640

636641
if (params.has("error")) {

0 commit comments

Comments
 (0)