Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/state/KindeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ export const KindeProvider = ({

const init = useCallback(async () => {
if (initRef.current) return;
await checkAuth({ domain, clientId });
initRef.current = true;
await checkAuth({ domain, clientId });
const params = new URLSearchParams(window.location.search);
Comment on lines 555 to 557
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling around checkAuth to avoid stuck loading state or silent failures

If checkAuth throws, init will abort before setting isLoading to false or proceeding to other branches. Catch and surface the error, but continue initialization so subsequent logic can still run.

Apply this diff:

   if (initRef.current) return;
   initRef.current = true;
-  await checkAuth({ domain, clientId });
+  try {
+    await checkAuth({ domain, clientId });
+  } catch (error) {
+    console.error("checkAuth error:", error);
+    mergedCallbacks.onError?.(
+      { error: "ERR_CHECK_AUTH", errorDescription: String(error) },
+      {},
+      contextValue,
+    );
+    // Intentionally continue; subsequent logic will determine auth state and set isLoading.
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
initRef.current = true;
await checkAuth({ domain, clientId });
const params = new URLSearchParams(window.location.search);
if (initRef.current) return;
initRef.current = true;
try {
await checkAuth({ domain, clientId });
} catch (error) {
console.error("checkAuth error:", error);
mergedCallbacks.onError?.(
{ error: "ERR_CHECK_AUTH", errorDescription: String(error) },
{},
contextValue,
);
// Intentionally continue; subsequent logic will determine auth state and set isLoading.
}
const params = new URLSearchParams(window.location.search);
🤖 Prompt for AI Agents
In src/state/KindeProvider.tsx around lines 555 to 557, wrap the await
checkAuth({ domain, clientId }) call in a try/catch so thrown errors don’t abort
initialization; on catch, record or log the error (e.g. set an error state or
processLogger.error) and ensure isLoading is set to false (or otherwise clear
loading) before continuing, then let the function proceed to the subsequent
logic (parsing URLSearchParams and other branches) so the component won’t remain
stuck in a loading state or silently fail.


if (params.has("error")) {
Expand Down