Skip to content

Commit

Permalink
JS: Fix clearing auth for React strict mode (#28923)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: c7297d7849c172027694a0838409bfb8945b91de
  • Loading branch information
xixixao authored and Convex, Inc. committed Aug 15, 2024
1 parent d1bfe3e commit a735dfb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions npm-packages/convex/src/react/ConvexAuthState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ export function ConvexProviderWithAuth({
setIsConvexAuthenticated((isConvexAuthenticated) =>
isConvexAuthenticated ? false : null,
);
// Clear timeout later, so that queries from
// unmounted child components unsubscribe first
// and rerun without auth on the server
setTimeout(() => client.clearAuth(), 0);
};
}
}, [isAuthenticated, fetchAccessToken, isLoading, client]);

// Clear auth later, so that queries from
// unmounted child components unsubscribe first
// and rerun without auth on the server
useLayoutEffect(() => {
if (isAuthenticated) {
return () => {
client.clearAuth();
};
}
}, [isAuthenticated, fetchAccessToken, isLoading, client]);
Expand Down

0 comments on commit a735dfb

Please sign in to comment.