-
Notifications
You must be signed in to change notification settings - Fork 1
feat(login) - mock implementation #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.1-pr.5.2dd0b1bPrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.1-pr.5.2dd0b1b"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.1-pr.5.2dd0b1b"
}
}
Preview published to npm registry — try new features instantly! |
Pull Request Review: Mock Login ImplementationSummaryThis PR implements a mock device code authentication flow for the CLI. The implementation demonstrates a good understanding of OAuth device flow patterns and includes proper structure with TypeScript path aliases, Zod validation, and error handling. ✅ StrengthsCode Organization
Type Safety & Validation
Error Handling
|
Pull Request Review: feat(login) - mock implementationOverviewThis PR implements a mock OAuth device code flow for the CLI login functionality. The implementation is well-structured and demonstrates good architectural decisions. However, there are several issues that should be addressed before merging. 🔴 Critical Issues1. Invalid Email in Mock Data (src/core/api/auth/client.ts:79)email: "sd.com",Issue: This is not a valid email address and will fail Zod validation. Fix: Use a valid email format: email: "test@example.com",2. Memory Leak in Production (src/core/api/auth/client.ts:13-16)const deviceCodeToTokenMap = new Map<
string,
{ startTime: number; readyAfter: number }
>();Issue: Module-level Map that never cleans up expired entries. Failed/abandoned login attempts will accumulate in memory indefinitely. Fix: Implement cleanup for expired entries or use a TTL-based cache library.
|
PR Review: feat(login) - mock implementationSummaryThis PR implements a basic device code OAuth flow for CLI authentication with a mock implementation. The code is well-structured with good separation of concerns, proper error handling, and type safety using Zod schemas. Positive Highlights
Issues & Recommendations1. Critical: Memory Leak in Mock ImplementationLocation: The const deviceCodeToTokenMap = new Map<
string,
{ startTime: number; readyAfter: number }
>();Issue: If users start authentication but don't complete it, the entries remain in memory forever. Recommendation: Add cleanup logic for expired entries or use a TTL-based cache. For the real implementation, this won't be needed as the state will be server-side. 2. Bug: Typo in Property NameLocation: if (elapsed < deviceInfo.readyAfter) {The property name appears to be 3. Code Quality: Duplicate Error Handling LogicLocation: The same error handling pattern is repeated in both if (error instanceof AuthValidationError) {
const issues = error.issues.map((i) => i.message).join(", ");
throw new Error(`Invalid response from server: ${issues}`);
}
if (error instanceof AuthApiError) {
throw new Error(`API error: ${error.message}`);
}Recommendation: Extract this into a utility function like function handleAuthError(error: unknown, context: string): never {
if (error instanceof AuthValidationError) {
const issues = error.issues.map((i) => i.message).join(", ");
throw new Error(`${context}: Invalid response from server: ${issues}`);
}
if (error instanceof AuthApiError) {
throw new Error(`${context}: ${error.message}`);
}
throw new Error(
`${context}: ${error instanceof Error ? error.message : String(error)}`
);
}4. Performance: Polling Interval Too AggressiveLocation: interval: 2000, // 2 second pollingIssue: 2-second polling for device code flow is quite aggressive. OAuth 2.0 Device Flow spec (RFC 8628) recommends 5+ seconds. Recommendation: Increase to 5000ms (5 seconds) to reduce unnecessary API calls and be more respectful of server resources. 5. Test CoverageLocation: N/A Issue: No tests were added for this significant new feature. The mock implementation makes this very testable! Recommendation: Add unit tests for:
Example test structure: describe('generateDeviceCode', () => {
it('should return valid device code response', async () => {
const response = await generateDeviceCode();
expect(response).toHaveProperty('deviceCode');
expect(response).toHaveProperty('userCode');
expect(response.expiresIn).toBeGreaterThan(0);
});
it('should validate response schema', async () => {
// Test with invalid mock data
});
});6. Security: Token StorageLocation: While
7. Minor: Inconsistent Spinner Stop MessagesLocation: s.stop("Device code generated"); // Line 21
s.stop("Authentication completed!"); // Line 92 (with exclamation)
s.stop("Authentication failed"); // Line 82 (in error path)Recommendation: Be consistent with punctuation and tone. Either always use exclamation marks for success or never. 8. Code Quality: Magic NumbersLocation: readyAfter: 5000, // What does this represent?
token: "mock-token-" + Date.now(), // Good for uniqueness but consider using crypto.randomUUID()Recommendation: Extract magic numbers to named constants and use const MOCK_AUTH_DELAY_MS = 5000; // Simulates server processing time
const MOCK_DEVICE_CODE_EXPIRY_SECONDS = 600;
// And use crypto for tokens
token: `mock-token-${crypto.randomUUID()}`,9. TypeScript: Consider Narrowing Error TypesLocation: if (error instanceof Error) {
throw error;
}This catches all Error types but then re-throws them. Consider being more specific about which errors should propagate vs be handled. 10. Dependencies: Node Version BumpLocation: The Node.js requirement was bumped from Recommendation: Document WHY this change was necessary. Was it for Additional ObservationsGood Practices Followed ✅
Build ConfigurationThe addition of Security AssessmentOverall: Low risk for a mock implementation, but some considerations for production:
Performance Considerations
Recommendations PriorityHigh Priority:
Medium Priority: Low Priority: VerdictThis is solid foundational work for the authentication system! The architecture is clean, types are strong, and error handling is thorough. The main concerns are around test coverage and a few implementation details that should be addressed before this pattern is used in production. Suggested Actions Before Merge:
Great job on the implementation! 🚀 |
PR Review: Mock Login ImplementationSummaryThis PR implements a mock device code OAuth flow for the CLI login functionality. The implementation follows the OAuth device authorization grant pattern commonly used by CLIs like GitHub CLI and Azure CLI. Code Quality & Best Practices✅ Strengths
|
Summary
Implement basic login mechanism in the CLI, we don't have server endpoints yet so this really just mocks it