This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BaseEntity, PrimaryGeneratedColumn, Entity, Column, Unique } from 'typeorm'; | |
@Entity() | |
@Unique(['email']) | |
export class User extends BaseEntity { | |
@PrimaryGeneratedColumn('uuid') | |
userID: string; | |
@Column({ nullable: true }) | |
firstname: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Repository, EntityRepository } from "typeorm"; | |
import { User } from "./user.entity"; | |
@EntityRepository(User) | |
export class UserRepository extends Repository<User> { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { AuthController } from './auth.controller'; | |
import { AuthService } from './auth.service'; | |
//Imported TypeOrmModule and UserRepository | |
import { TypeOrmModule } from '@nestjs/typeorm'; | |
import { UserRepository } from './user.repository'; | |
@Module({ | |
//updated imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { UserRepository } from './user.repository'; | |
import { InjectRepository } from '@nestjs/typeorm'; | |
@Injectable() | |
export class AuthService { | |
//new code below | |
constructor( | |
@InjectRepository(UserRepository) | |
private userRepository: UserRepository, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AuthSignUpDto { | |
email: string; | |
password: string; | |
firstname: string; | |
lastname: string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IsString, IsEmail, MinLength, Matches } from 'class-validator'; | |
export class AuthSignUpDto { | |
@IsEmail() | |
email: string; | |
@IsString() | |
@MinLength(8) | |
//regex for password to contain atleast one uppercase, lowercase, number and special character | |
@Matches(/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Repository, EntityRepository } from 'typeorm'; | |
import { User } from './user.entity'; | |
import { AuthSignUpDto } from './dto/auth-signup.dto'; | |
import { | |
ConflictException, | |
InternalServerErrorException, | |
} from '@nestjs/common'; | |
@EntityRepository(User) | |
export class UserRepository extends Repository<User> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { UserRepository } from './user.repository'; | |
import { InjectRepository } from '@nestjs/typeorm'; | |
import { AuthSignUpDto } from './dto/auth-signup.dto'; | |
@Injectable() | |
export class AuthService { | |
constructor( | |
@InjectRepository(UserRepository) | |
private userRepository: UserRepository, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from '@nestjs/common'; | |
import { AuthService } from './auth.service'; | |
import { AuthSignUpDto } from './dto/auth-signup.dto'; | |
@Controller('auth') | |
export class AuthController { | |
//injection of Authservice in the constructor | |
constructor(private authService: AuthService) {} | |
//new signUp method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm i --save bcrypt @types/bcrypt |