add login flow for waiting list demo app

This commit is contained in:
Abdalhamid Alhamad
2025-03-04 14:42:02 +03:00
parent 54ce5b022d
commit 9b5f863577
16 changed files with 184 additions and 21 deletions

View File

@ -56,6 +56,8 @@ export class NotificationsService {
scope: NotificationScope.USER_INVITED,
channel: NotificationChannel.EMAIL,
});
console.log('++++++++++++++++++++++++=');
console.log(data);
return this.eventEmitter.emit(EventType.NOTIFICATION_CREATED, notification, data.data);
}
@ -71,7 +73,7 @@ export class NotificationsService {
this.logger.log(`emitting ${EventType.NOTIFICATION_CREATED} event`);
return this.eventEmitter.emit(EventType.NOTIFICATION_CREATED, notification);
return this.eventEmitter.emit(EventType.NOTIFICATION_CREATED, notification, { otp });
}
private async sendPushNotification(userId: string, title: string, body: string) {

View File

@ -24,6 +24,9 @@ export class Otp {
@Column('varchar', { name: 'user_id' })
userId!: string;
@Column('boolean', { default: false, name: 'is_used' })
isUsed!: boolean;
@ManyToOne(() => User, (user) => user.otp, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user!: User;

View File

@ -1,4 +1,5 @@
export enum OtpScope {
VERIFY_PHONE = 'VERIFY_PHONE',
FORGET_PASSWORD = 'FORGET_PASSWORD',
LOGIN = 'LOGIN',
}

View File

@ -14,7 +14,7 @@ export class OtpRepository {
createOtp(otp: Partial<Otp>) {
return this.otpRepository.save(
this.otpRepository.create({
userId: otp.userId,
userId: otp.userId ?? undefined,
value: otp.value,
scope: otp.scope,
otpType: otp.otpType,
@ -31,10 +31,15 @@ export class OtpRepository {
value: otp.value,
otpType: otp.otpType,
expiresAt: MoreThan(new Date()),
isUsed: false,
},
order: {
createdAt: 'DESC',
},
});
}
updateOtp(id: string, data: Partial<Otp>) {
return this.otpRepository.update(id, data);
}
}

View File

@ -35,11 +35,16 @@ export class OtpService {
if (!otp) {
this.logger.error(
`OTP value ${verifyOtpRequest.value} not found for ${verifyOtpRequest.userId} and ${verifyOtpRequest.otpType}`,
`OTP value ${verifyOtpRequest.value} not found for ${verifyOtpRequest.userId} and ${verifyOtpRequest.otpType} or used`,
);
return false;
}
const { affected } = await this.otpRepository.updateOtp(otp.id, { isUsed: true });
console.log('+++++++++++++++++++++++++++');
console.log(affected);
this.logger.log(`OTP verified successfully for ${verifyOtpRequest.userId}`);
return !!otp;
}