refactor: enforce passkey authentication for user switching on all platforms - #1201
Conversation
…atforms - Make handleSelectUserById async and require passkey auth on all platforms - Remove legacy username-based user selection (selectUser/handleSelectUser) - Add error toast notifications when passkey authentication fails - Simplify TurnkeyProvider to fallback to single user when none selected - Improve error handling with user selection reversion on auth failure - Remove SDK logout call from handleLogout to prevent race conditions Breaking changes: - handleSelectUserById is now async and always requires passkey authentication - handleSelectUser function removed from useUser hook and store Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Pull Request ReviewOverviewThis PR enforces passkey authentication for user switching across all platforms, removing the legacy username-based selection system. The refactor improves security and simplifies the codebase. ✅ Positive Changes
🐛 Issues & BugsCritical Issues
Moderate Issues
⚡ Performance Considerations
🔒 Security Concerns
🧪 Test CoverageMissing Tests: This PR lacks test coverage for:
Recommendation: Add unit tests for
E2E Testing: Consider adding a Playwright test for the complete user switching flow. 📋 Additional Recommendations
SummaryThis is a solid refactor that improves security and simplifies the codebase. However, there are several critical issues that should be addressed before merging: Must Fix Before Merge:
Should Fix:
Nice to Have:
Overall assessment: Needs Revisions - The security improvement is excellent, but the error handling needs work before this can be safely merged. Review conducted by Claude Code |
- Eliminated console.log statements for authedUser and userId to clean up the code and reduce unnecessary logging during user authentication.
PR Review: Enforce Passkey Authentication for User SwitchingSummaryThis PR improves security by requiring passkey authentication when switching users across all platforms (previously only on web). It also cleans up legacy username-based selection code and improves error handling. ✅ StrengthsSecurity Improvements
Code Quality
🔍 Issues & ConcernsCritical Issues1. Potential Breaking Change in TurnkeyProvider (components/TurnkeyProvider.tsx:20) const selectedUser = users.find(u => u.selected) ?? (users.length === 1 ? users[0] : undefined);
const selectedUser = users.find(u => u.selected) ??
(users.length === 1 && users[0].credentialId ? users[0] : undefined);2. Missing Error Type Safety (app/welcome.tsx:45) } catch (error: any) {
} catch (error: unknown) {
const message = error instanceof Error ? error.message : 'Please try again';
Toast.show({
type: 'error',
text1: 'Authentication failed',
text2: message,
// ...
});
}3. Silent Error Swallowing in handleSelectUserById (hooks/useUser.ts:495) } catch (error) {
// Revert to previous user or clear selection on auth failure
if (previousUserId) {
selectUserById(previousUserId);
} else {
unselectUser();
}
// Don't navigate on error - stay on welcome screen
}
} catch (error) {
if (previousUserId) {
selectUserById(previousUserId);
} else {
unselectUser();
}
throw error; // Re-throw so caller can handle
}Medium Priority Issues4. Inconsistent Error Handling - Missing httpClient Check (hooks/useUser.ts:477-479) if (!httpClient) {
throw new Error('Turnkey client is not initialized. Please wait and try again.');
}
5. Potential Race Condition with selectUserById (hooks/useUser.ts:489) if (authedUser?._id && authedUser._id === userId) {
selectUserById(authedUser._id);
}
if (authedUser?._id && authedUser._id === userId) {
selectUserById(authedUser._id);
router.replace(path.HOME);
} else {
throw new Error('Authentication returned a different user');
}6. Missing Dependency in useCallback (hooks/useUser.ts:505) [selectUserById, clearKycLinkId, router, user, unselectUser, users, httpClient, login],
Minor Issues7. Inconsistent Property Access (hooks/useUser.ts:489) if (authedUser?._id && authedUser._id === userId)vs the User type which uses
8. Redundant selectedUser Check (hooks/useUser.ts:461-471) const selectedUser = users.find(u => u.userId === userId);Then later: track(TRACKING_EVENTS.WELCOME_USER, {
user_id: selectedUser?._id,
username: selectedUser?.username,
email: selectedUser?.email,
});
🧪 Testing ConcernsMissing Test CoverageThe README notes that "the project does not have a formal test suite configured." For changes this critical to authentication, testing is essential: Recommended Tests:
Manual Testing RequiredSince automated tests don't exist, ensure manual testing covers:
🔒 Security AnalysisPositive Security Changes
Security Considerations
📊 Performance ConsiderationsPositive
Concerns
🎯 RecommendationsRequired Changes
Strongly Recommended
Nice to Have
📝 Code Style & ConventionsFollowing the README guidelines:
Final VerdictThis PR makes important security improvements, but has several issues that should be addressed before merging: Merge Status: The authentication logic improvements are solid, but the issues around error handling, property naming inconsistencies, and the TurnkeyProvider fallback logic need to be resolved. The lack of test coverage for such critical authentication code is also concerning. Priority:
Great work on improving security across platforms! The changes are well-structured and the error handling pattern is sound - just needs a few refinements. |
Breaking changes: