I'm a junior full-stack developer from Alexandria, Egypt. This is another post about FaceMark, my face-recognition attendance system (a NestJS API plus a Python AI service), and this time it's about the auth service: what actually happens when someone registers or logs in.
The save is the last thing that happens
Registering is a transaction, not a save call
My register method doesn't call save() on a new user right away. It opens a transaction first, because two weird cases live inside it:
async register ( registerDto : RegisterDto ) { const { username , password , role } = registerDto ;
return await this . dataSource . transaction ( async ( manager ) => { const transactionalRepo = manager . getRepository ( UserAccount ) ;
const existingUser = await transactionalRepo . findOne ( { where : { username } , } ) ;
if ( existingUser ) { if ( ! existingUser .…