implement auth login and register with MongoDB
- Add AuthController login/register endpoints with error handling - Implement AuthService with password validation and user creation - Add MongoUserRepository with findByEmail and create methods - Implement password hashing with bcrypt - Add dotenv for environment variable support - Add Docker Compose setup for MongoDB + Mongo Express - Stub AuthMiddleware with fake user for testing - Update CLAUDE.md with implementation status
This commit is contained in:
@@ -7,11 +7,33 @@ export class AuthService {
|
||||
constructor(private userRepo: UserRepository) {}
|
||||
|
||||
async login(data: LoginDTO): Promise<AuthResponse> {
|
||||
throw new Error('Not implemented');
|
||||
const user = await this.userRepo.findByEmail(data.email);
|
||||
if (!user || !user.passwordHash) {
|
||||
throw new Error('Invalid credentials');
|
||||
}
|
||||
|
||||
const isValid = await password.compare(data.password, user.passwordHash);
|
||||
if (!isValid) {
|
||||
throw new Error('Invalid credentials');
|
||||
}
|
||||
|
||||
return { user, accessToken: '' };
|
||||
}
|
||||
|
||||
async register(data: CreateUserDTO): Promise<AuthResponse> {
|
||||
throw new Error('Not implemented');
|
||||
const existingUser = await this.userRepo.findByEmail(data.email);
|
||||
if (existingUser) {
|
||||
throw new Error('Email already exists');
|
||||
}
|
||||
|
||||
const passwordHash = await password.hash(data.password);
|
||||
const user = await this.userRepo.create({
|
||||
email: data.email,
|
||||
displayName: data.displayName,
|
||||
passwordHash,
|
||||
});
|
||||
|
||||
return { user, accessToken: '' };
|
||||
}
|
||||
|
||||
async refreshToken(refreshToken: string): Promise<AuthResponse> {
|
||||
|
||||
Reference in New Issue
Block a user