top of page

How To Setup an Auth Module, User Entity & User Repository

Creating a new module

nest g module auth

nest for nest

g for generate

auth for the file name

Creating a controller

nest g controller auth

nest g service auth

For Connecting Database

  1. Create a file Entity.ts under auth

Decorators can be defined for either a class, a method or a property. (@Entity)

import { BaseEntity, Column, PrimaryGeneratedColumn } from "typeorm"; export class User extends BaseEntity { @PrimaryGeneratedColumn() id: number; @Column() username: string; @Column() password: string; }

Base Class Repository for TypeORM ---

Repository for type USER === Repository<User>

Auth Module

we want to show that database which we are going to use throughout our module soo

introducing the Repository under Module section

import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeORMError } from 'typeorm'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; import { UserRepository } from './user.repository'; @Module({ imports: [ TypeOrmModule.forFeature([UserRepository]), ], controllers: [AuthController], providers: [AuthService], }) export class AuthModule {}

5 views0 comments

Recent Posts

See All


SQL UNION Operator UNION operator is used to combine the results of two or more SELECT statements Every SELECT statement within UNION must have the same number of columns The columns must also have si


JOIN clause is used to combine rows from two or more tables. INNER JOIN === selects records that have matching values in both tables SELECT Orders.OrderID, Customers.CustomersID, Orders.OrdersDate FRO


bottom of page