Skip to content

Commit 4494f15

Browse files
authored
Merge pull request #133 from SudiptaPaul-31/feat/move-usecase
Moved to Auth Module use-cases folder
2 parents 4589688 + 3dc3454 commit 4494f15

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/useCase/emailVerificationUsecase.ts renamed to src/modules/auth/use-cases/email-verification.usecase.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { IUserRepository } from '../repository/IUserRepository';
1+
import { IUserRepository } from '../../../repository/IUserRepository';
22
import { randomBytes } from 'crypto';
3-
import { sendVerificationEmail } from '../utils/email.utils';
3+
import { sendVerificationEmail } from '../../../utils/email.utils';
44

55
export class EmailVerificationUseCase {
66
constructor(private userRepository: IUserRepository) {}
@@ -17,17 +17,21 @@ export class EmailVerificationUseCase {
1717
await this.userRepository.updateVerificationToken(user.id, token, expires);
1818

1919
const verificationLink = `http://localhost:3000/auth/verify-email?token=${token}`;
20-
21-
20+
2221
await sendVerificationEmail(user.email, verificationLink);
2322
}
2423

2524
async verifyEmail(token: string): Promise<void> {
2625
const user = await this.userRepository.findByVerificationToken(token);
27-
if (!user) throw new Error('Invalid or expired token');
28-
29-
if (user.verificationTokenExpires && new Date() > user.verificationTokenExpires) {
30-
throw new Error('Token expired. Please request a new verification email.');
26+
if (!user) throw new Error("Invalid or expired token");
27+
28+
if (
29+
user.verificationTokenExpires &&
30+
new Date() > user.verificationTokenExpires
31+
) {
32+
throw new Error(
33+
'Token expired. Please request a new verification email.'
34+
);
3135
}
3236

3337
await this.userRepository.updateVerificationStatus(user.id);

src/useCase/resendEmailVericationUseCase.ts renamed to src/modules/auth/use-cases/resend-email-verification.usecase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ResendVerificationUseCase {
1717
await this.userRepository.updateVerificationToken(user.id, token, expires);
1818

1919
const verificationLink = `http://localhost:3000/auth/verify-email?token=${token}`;
20-
20+
2121
// Assuming sendVerificationEmail(email, verificationLink) is the correct signature
2222
await sendVerificationEmail(user.email, verificationLink);
2323
}

0 commit comments

Comments
 (0)