diff --git a/src/app.module.ts b/src/app.module.ts index 7e0ca7d3..d59995ce 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,10 +1,10 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { UsersModule } from './users/users.module'; +import { AuthModule } from './auth/auth.module'; import { PropertiesModule } from './properties/properties.module'; import { PrismaModule } from './database/prisma.module'; import { AppController } from './app.controller'; -import { AuthModule } from './auth/auth.module'; @Module({ imports: [ @@ -14,8 +14,8 @@ import { AuthModule } from './auth/auth.module'; }), PrismaModule, UsersModule, - PropertiesModule, AuthModule, + PropertiesModule, ], controllers: [AppController], }) diff --git a/src/auth/dto/auth.dto.ts b/src/auth/dto/auth.dto.ts index 584e90ef..8b7b2ed2 100644 --- a/src/auth/dto/auth.dto.ts +++ b/src/auth/dto/auth.dto.ts @@ -5,6 +5,7 @@ import { IsOptional, IsString, MinLength, + Matches, } from 'class-validator'; export class RegisterDto { @@ -12,7 +13,10 @@ export class RegisterDto { email: string; @IsString() - @MinLength(8) + @MinLength(8, { message: 'Password must be at least 8 characters long' }) + @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, { + message: 'Password is too weak. It must contain at least one uppercase letter, one lowercase letter, and at least one number or special character.', + }) password: string; @IsString() diff --git a/src/auth/dto/register.dto.ts b/src/auth/dto/register.dto.ts new file mode 100644 index 00000000..e9908ebe --- /dev/null +++ b/src/auth/dto/register.dto.ts @@ -0,0 +1,26 @@ +import { IsEmail, IsNotEmpty, IsString, MinLength, Matches } from 'class-validator'; + +export class RegisterDto { + @IsEmail({}, { message: 'Please provide a valid email address' }) + @IsNotEmpty({ message: 'Email is required' }) + email: string; + + @IsString() + @MinLength(8, { message: 'Password must be at least 8 characters long' }) + @Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, { + message: 'Password is too weak. It must contain at least one uppercase letter, one lowercase letter, and at least one number or special character.', + }) + password: string; + + @IsString() + @IsNotEmpty({ message: 'First name is required' }) + firstName: string; + + @IsString() + @IsNotEmpty({ message: 'Last name is required' }) + lastName: string; + + @IsString() + @IsNotEmpty({ message: 'Phone number is required' }) + phone: string; +}