fix(platform): use safeGetAuthUser for graceful unauthenticated handling#500
Conversation
…cated users gracefully
getAuthUser throws ConvexError("Unauthenticated") instead of returning null,
making the null checks in these functions dead code. Switch to safeGetAuthUser
which returns undefined, allowing queries to return null/false as intended.
Greptile SummaryReplaced
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| services/platform/convex/accounts/helpers.ts | replaced getAuthUser with safeGetAuthUser in 3 query functions to handle unauthenticated users gracefully |
| services/platform/convex/onedrive/with_microsoft_token.ts | switched to safeGetAuthUser to return error object instead of throwing for unauthenticated users |
| services/platform/convex/organizations/get_current_organization.ts | changed to safeGetAuthUser allowing graceful null return for unauthenticated access |
| services/platform/convex/organizations/get_organization.ts | updated to safeGetAuthUser to return null instead of throwing when unauthenticated |
| services/platform/convex/sso_providers/get_auth_user.ts | switched to safeGetAuthUser for consistent null handling without exceptions |
| services/platform/convex/sso_providers/get_microsoft_token.ts | replaced getAuthUser with safeGetAuthUser to gracefully return null for unauthenticated queries |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Query/Helper Function Called] --> B{User Authenticated?}
B -->|No - Before PR| C[getAuthUser throws ConvexError]
C --> D[Error Toast in UI]
B -->|No - After PR| E[safeGetAuthUser returns undefined]
E --> F[Null check catches it]
F --> G[Return null/false gracefully]
G --> H[UI shows fallback state]
B -->|Yes - Both versions| I[Returns user object]
I --> J[Continue with business logic]
J --> K[Return actual data]
Last reviewed commit: 5b619c3
📝 WalkthroughWalkthroughThis pull request systematically replaces calls to Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@services/platform/convex/accounts/helpers.ts`:
- Around line 50-53: getMicrosoftAccount currently logs a console.warn when
safeGetAuthUser returns null even though unauthenticated is a valid,
non-exceptional path; remove the noisy warning and return null silently (or use
debug-only logging) so unauthenticated queries don't spam logs. Locate the
getMicrosoftAccount function and the authComponent.safeGetAuthUser call and
delete or replace the console.warn('getMicrosoftAccount: No authenticated user')
with no-op or a debug logger call, and ensure any similar handling of
authComponent.getAuthUser in Convex query handlers follows the same
silent/empty-catch pattern.
Summary
authComponent.getAuthUser()throwsConvexError("Unauthenticated")instead of returningnull, making null checks in query/helper functions dead codesafeGetAuthUser()which returnsundefinedinstead of throwing, allowing queries to gracefully returnnull/falsefor unauthenticated usersTest plan
hasMicrosoftAccountquery no longer throwsUnauthenticatederror in Convex logsnpx tsc --noEmit)🤖 Generated with Claude Code
Summary by CodeRabbit