Skip to content

Commit a735dfb

Browse files
xixixaoConvex, Inc.
authored and
Convex, Inc.
committed
JS: Fix clearing auth for React strict mode (#28923)
GitOrigin-RevId: c7297d7849c172027694a0838409bfb8945b91de
1 parent d1bfe3e commit a735dfb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

npm-packages/convex/src/react/ConvexAuthState.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,17 @@ export function ConvexProviderWithAuth({
105105
setIsConvexAuthenticated((isConvexAuthenticated) =>
106106
isConvexAuthenticated ? false : null,
107107
);
108-
// Clear timeout later, so that queries from
109-
// unmounted child components unsubscribe first
110-
// and rerun without auth on the server
111-
setTimeout(() => client.clearAuth(), 0);
108+
};
109+
}
110+
}, [isAuthenticated, fetchAccessToken, isLoading, client]);
111+
112+
// Clear auth later, so that queries from
113+
// unmounted child components unsubscribe first
114+
// and rerun without auth on the server
115+
useLayoutEffect(() => {
116+
if (isAuthenticated) {
117+
return () => {
118+
client.clearAuth();
112119
};
113120
}
114121
}, [isAuthenticated, fetchAccessToken, isLoading, client]);

0 commit comments

Comments
 (0)