Fix potential race condition for sign out#8
Conversation
WalkthroughThe pull request modifies the Changes
Sequence DiagramsequenceDiagram
participant User
participant AccountMenu
participant BillingService
participant SessionStorage
participant Navigation
User->>AccountMenu: Trigger Sign Out
AccountMenu->>BillingService: Clear Billing Token
alt Token Clearance Successful
BillingService-->>AccountMenu: Token Cleared
else Token Clearance Failed
AccountMenu->>SessionStorage: Manually Remove Token
end
AccountMenu->>Navigation: Navigate to Home Page
Note over AccountMenu: Handle and Log Any Errors
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Deploying maple with
|
| Latest commit: |
b81cada
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5a7d921f.maple-ca8.pages.dev |
| Branch Preview URL: | https://logout-improvements.maple-ca8.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
frontend/src/components/AccountMenu.tsx (2)
96-115: Enhance error handling with specific error types.The current implementation catches all errors generically. Consider handling specific error types differently for better debugging and user experience.
Here's a suggested implementation:
async function signOut() { try { // Try to clear billing token first try { getBillingService().clearToken(); } catch (error) { + if (error instanceof TypeError) { + console.warn('Billing service not initialized:', error); + } else { + console.error('Failed to clear billing token:', error); + } // Fallback to direct session storage removal if billing service fails sessionStorage.removeItem("maple_billing_token"); } // Sign out from OpenSecret - await os.signOut(); + try { + await os.signOut(); + } catch (error) { + console.error('OpenSecret sign out failed:', error); + throw error; // Re-throw to trigger the fallback + } // Navigate after everything is done await router.invalidate(); await router.navigate({ to: "/" }); } catch (error) { - console.error("Error during sign out:", error); + console.error("Critical error during sign out:", error); + // Notify user before reload + alert('An error occurred during sign out. The page will reload.'); // Force reload as last resort window.location.href = "/"; } }
97-103: Improve billing token clearing robustness.The billing token clearing could be more robust by ensuring the billing service is properly initialized before use.
Here's a suggested implementation:
// Try to clear billing token first try { - getBillingService().clearToken(); + const billingService = getBillingService(); + if (!billingService) { + throw new Error('Billing service not initialized'); + } + await billingService.clearToken(); } catch (error) { // Fallback to direct session storage removal if billing service fails sessionStorage.removeItem("maple_billing_token"); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/src/components/AccountMenu.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Cloudflare Pages
2f363ce to
b81cada
Compare
Summary by CodeRabbit