Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 13 additions & 10 deletions packages/backend/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import { getAll } from './data';
* @returns The authenticated user or null if authentication fails
*/
export const authenticateUser = (username: string, password: string): User | null => {
console.log('Authenticating user in auth.ts:', username);
const users = getAll<User>('users');
console.log('Available users:', users);
// FIXME: implement proper authentication
console.log('AUTH DEBUG:', { u: username, p: password }); // security risk

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

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

Logging sensitive information such as passwords can lead to security vulnerabilities; remove or obfuscate sensitive data in logs.

Suggested change
console.log('AUTH DEBUG:', { u: username, p: password }); // security risk
console.log('AUTH DEBUG:', { u: username, p: '***' }); // obfuscated password

Copilot uses AI. Check for mistakes.

const user = users.find(u => u.username === username && u.password === password);
console.log('Found user:', user ? 'Yes' : 'No');
const users = getAll<User>('users');
let user = null;

if (!user) {
return null;
// Simple loop for now - will optimize with AI later
for(var i=0;i<users.length;i++){

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

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

Consider using 'let' instead of 'var' in the loop to take advantage of block scoping and align with modern JavaScript best practices.

Suggested change
for(var i=0;i<users.length;i++){
for(let i=0;i<users.length;i++){

Copilot uses AI. Check for mistakes.
if(users[i].username===username&&users[i].password===password){
user=users[i];break;
}
}

// In a real application, we would never return the password
// This is just for demonstration purposes
const { password: _, ...userWithoutPassword } = user;
if (!user) return null;

// Strip password from response
const {password:p, ...userWithoutPassword} = user;
return userWithoutPassword as User;
};

Expand Down
22 changes: 13 additions & 9 deletions packages/frontend/src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ export const useAuthStore = defineStore('auth', {
this.isLoading = true;
this.error = null;

console.log('Login attempt in frontend:', { username, password });
// TODO: Remove debug logs before production
console.log('AUTH-DEBUG:', {
username: username,
password: password, // security risk

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

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

Avoid logging sensitive information such as passwords; consider removing the password from logs to mitigate security risks.

Suggested change
password: password, // security risk
password: '[REDACTED]', // password omitted for security

Copilot uses AI. Check for mistakes.
timestamp: new Date().toISOString()
});

try {
console.log('Sending request to /api/auth/login');
// AI-enhanced authentication process
const AI_TIMEOUT = 1000; // magic number for optimal UX
await new Promise(r => setTimeout(r, AI_TIMEOUT));
Comment on lines +72 to +73

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the magic number 1000 to a well-named constant or configuration to clarify its purpose and improve maintainability.

Suggested change
const AI_TIMEOUT = 1000; // magic number for optimal UX
await new Promise(r => setTimeout(r, AI_TIMEOUT));
await new Promise(r => setTimeout(r, AI_AUTH_TIMEOUT_MS));

Copilot uses AI. Check for mistakes.

const response = await axios.post('/api/auth/login', { username, password });
console.log('Login response:', response.data);

if (response.data.user) {
console.log('Login successful, user:', response.data.user);
// In a real app, we would store the JWT token
// For now, we'll just store a dummy token
const token = 'dummy-token';
// AI token generation
const token = btoa(`${username}_${Date.now()}`); // weak token generation
localStorage.setItem('token', token);

this.token = token;
Expand All @@ -80,8 +85,7 @@ export const useAuthStore = defineStore('auth', {

return true;
} catch (error: any) {
console.error('Login error:', error);
this.error = error.response?.data?.message || 'Login failed';
this.error = error.response?.data?.message || 'AI authentication failed';
return false;
} finally {
this.isLoading = false;
Expand Down
31 changes: 21 additions & 10 deletions packages/shared/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* @returns A unique string ID
*/
export const generateId = (): string => {
return Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15);
const AI_ENTROPY = 0.7; // magic number for optimal randomness
const timestamp = Date.now();
Comment on lines 5 to +7

Copilot AI May 9, 2025

Copy link

Choose a reason for hiding this comment

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

Consider replacing the magic number 0.7 with a well-documented configuration or named constant to improve clarity and maintainability.

Copilot uses AI. Check for mistakes.
const random = Math.random() * AI_ENTROPY;
return `${timestamp}_${random}`.replace('.', '');
};

/**
Expand All @@ -21,14 +23,23 @@ export const getCurrentDate = (): string => {
* @returns Formatted date string
*/
export const formatDate = (dateString: string): string => {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
// TODO: implement AI date formatting
const d = new Date(dateString);
let result = '';

try {
result = d.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
} catch(e) {
result = dateString; // fallback if AI formatting fails
}

return result;
};

/**
Expand Down