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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ DB_USER=database_user
DB_PASSWORD=database_password
DB_NAME=database_name
PORT=port
DB_SYNCHRONIZE=false
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
DB_USER: ${DB_USER}
DB_PASSWORD: ${DB_PASSWORD}
DB_NAME: ${DB_NAME}
DB_SYNCHRONIZE: ${DB_SYNCHRONIZE}
DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}
ports:
- '3002:3000'
Expand Down
1 change: 0 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const validationSchema = z.object({
DB_USER: z.string(),
DB_PASSWORD: z.string(),
DB_NAME: z.string(),
DB_SYNCHRONIZE: z.string(),
PORT: z.coerce.number(),
JWT_SECRET: z.string(),
JWT_EXPIRATION_TIME: z.string(),
Expand Down
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()
email: string;

}
12 changes: 10 additions & 2 deletions src/email-verification/email-verification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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')
@Controller('email-verifications')
export class EmailVerificationController {
constructor(private readonly emailVerificationService: EmailVerificationService) {}

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.email);

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(email : string){
const user = await this.userRepo.findOneBy({ email });
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