mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-26 06:09:41 +00:00
add login flow for waiting list demo app
This commit is contained in:
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,5 @@
|
||||
export enum OtpScope {
|
||||
VERIFY_PHONE = 'VERIFY_PHONE',
|
||||
FORGET_PASSWORD = 'FORGET_PASSWORD',
|
||||
LOGIN = 'LOGIN',
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user