typescriptNestJSadvanced
NestJS Injectable Auth Service
NestJS injectable service with constructor injection and async validation
By ApeType Staff·13 lines·467 characters·1,420 total attempts
import { Injectable, UnauthorizedException } from "@nestjs/common";
@Injectable()
export class AuthService {
constructor(private readonly userRepository: UserRepository) {}
async validateUser(email: string, pass: string): Promise<UserOutput> {
const user = await this.userRepository.findByEmail(email);
if (!user || !(await verifyHash(pass, user.passwordHash))) {
throw new UnauthorizedException("Invalid credentials provided");
}
return sanitizeUser(user);
}
}
TRANSCRIBE
Ready when you are.
Test your muscle memory and transcription speed against this exact snippet.
Start Typing
Tip: Press Esc anytime to restart
Best runs on this snippet
No recorded runs yet. Be the first to type this snippet!