Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/email-verification/dto/resend-email.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IsString } from 'class-validator';

export class ResendEmailDto {

@IsString()
id: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to email


}
10 changes: 9 additions & 1 deletion src/email-verification/email-verification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequestEmailDto } from './dto/request-email.dto';
import { ResendEmailDto } from './dto/resend-email.dto';
import { EmailVerificationService } from './email-verification.service';
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Post, Req } from '@nestjs/common';

@Controller('email-verification')
export class EmailVerificationController {
Expand All @@ -11,4 +12,11 @@ export class EmailVerificationController {
await this.emailVerificationService.sendEmail(dto.email);
return { message: 'Verification link sent to your email' };
}

@Post('resend-email')
async resendVerificationLink(@Body() dto: ResendEmailDto) {
await this.emailVerificationService.resendVerificationLink(dto.id);

return 'Verification link has been sent to your email again';
}
}
12 changes: 11 additions & 1 deletion src/email-verification/email-verification.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { EmailVerification } from './entities/email-verification.entity';
Expand Down Expand Up @@ -55,4 +55,14 @@ export class EmailVerificationService {

await this.emailVerificationRepo.save({ user, token, expires_at });
}

public async resendVerificationLink(id : string){
const user = await this.userRepo.findOneBy({ id });
if (!user) throw new Error('User not found');

if(user.verified_at){
throw new BadRequestException('Email already verified');
}
await this.sendEmail(user.email)
}
}
2 changes: 1 addition & 1 deletion src/migrations/1760485409896-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
export class Users1760485409896 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "users" (
`CREATE TABLE IF NOT EXISTS "users" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
"name" VARCHAR(255) NOT NULL,
"username" VARCHAR(255) UNIQUE NOT NULL,
Expand Down