Fix pre-commit script to properly handle multiple files and resolve ESLint warnings

This commit is contained in:
William Valentin
2025-09-07 13:34:39 -07:00
parent 8fa2d3fb60
commit 315303b120
33 changed files with 561 additions and 404 deletions

View File

@@ -1,6 +1,5 @@
import { authService } from '../auth.service';
import { AccountStatus } from '../auth.constants';
import { User } from '../../../types';
// Helper to clear localStorage and reset the mock DB before each test
beforeEach(() => {

View File

@@ -1,5 +1,4 @@
import { EmailVerificationService } from '../emailVerification.service';
import { dbService } from '../../couchdb.factory';
jest.mock('../../couchdb.factory');
jest.mock('../../email');

View File

@@ -31,7 +31,7 @@ export const authenticate = (
};
// Security: Role-based authorization middleware
export const authorize = (...allowedRoles: string[]) => {
export const authorize = (..._allowedRoles: string[]) => {
return (req: Request, res: Response, next: NextFunction) => {
try {
// Security: Check if user exists in request

View File

@@ -1,7 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import { dbService } from '../../services/couchdb.factory';
import { AccountStatus } from './auth.constants';
import { User } from '../../types';
import { AuthenticatedUser } from './auth.types';
import { EmailVerificationService } from './emailVerification.service';
@@ -33,17 +31,17 @@ const authService = {
},
async login(input: { email: string; password: string }) {
console.log('🔐 Login attempt for:', input.email);
console.warn('🔐 Login attempt for:', input.email);
// Find user by email
const user = await dbService.findUserByEmail(input.email);
if (!user) {
console.log('❌ User not found for email:', input.email);
console.warn('❌ User not found for email:', input.email);
throw new Error('User not found');
}
console.log('👤 User found:', {
console.warn('👤 User found:', {
email: user.email,
hasPassword: !!user.password,
role: user.role,
@@ -53,25 +51,25 @@ const authService = {
// Check if user has a password (email-based account)
if (!user.password) {
console.log('❌ No password found - OAuth account');
console.warn('❌ No password found - OAuth account');
throw new Error(
'This account was created with OAuth. Please use Google or GitHub to sign in.'
);
}
// Simple password verification (in production, use bcrypt)
console.log('🔍 Comparing passwords:', {
console.warn('🔍 Comparing passwords:', {
inputPassword: input.password,
storedPassword: user.password,
match: user.password === input.password,
});
if (user.password !== input.password) {
console.log('❌ Password mismatch');
console.warn('❌ Password mismatch');
throw new Error('Invalid password');
}
console.log('✅ Login successful for:', user.email);
console.warn('✅ Login successful for:', user.email);
// Return mock tokens for frontend compatibility
return {
@@ -204,7 +202,10 @@ const authService = {
const resetTokens = JSON.parse(
localStorage.getItem('password_reset_tokens') || '[]'
);
const resetToken = resetTokens.find((t: any) => t.token === token);
const resetToken = resetTokens.find(
(t: { token: string; userId: string; email: string; expiresAt: Date }) =>
t.token === token
);
if (!resetToken) {
throw new Error('Invalid or expired reset token');
@@ -227,7 +228,10 @@ const authService = {
);
// Remove used token
const filteredTokens = resetTokens.filter((t: any) => t.token !== token);
const filteredTokens = resetTokens.filter(
(t: { token: string; userId: string; email: string; expiresAt: Date }) =>
t.token !== token
);
localStorage.setItem(
'password_reset_tokens',
JSON.stringify(filteredTokens)