Logo
Section 1 / 7

配置认证模块、控制器、服务和仓库

学习如何使用 NestJS 生成身份验证所需的文件。

导入

配置认证模块、控制器、服务和仓库

学习如何使用 NestJS 生成身份验证所需的文件。

1nest g module auth
1nest g co auth --no-spec
1nest g s auth --no-spec
  • id
  • email(必须唯一,避免重复)
  • password
1import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; 2 3@Entity() 4export class User { 5 @PrimaryGeneratedColumn() 6 id: number 7 8 @Column({ unique: true }) 9 email: string 10 11 @Column() 12 password: string 13}
1import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; 2 3@Entity() 4export class User { 5 @PrimaryGeneratedColumn() 6 id: number 7 8 @Column({ unique: true }) 9 email: string 10 11 @Column() 12 password: string 13}
1import { TypeOrmModule } from '@nestjs/typeorm'; 2import { AuthService } from './auth.service'; 3import { AuthController } from './auth.controller'; 4import { User } from './entities/user.entity'; 5 6@Module({ 7 providers: [AuthService], 8 controllers: [AuthController], 9 imports: [TypeOrmModule.forFeature([User])], 10}) 11export class AuthModule {}
1import { TypeOrmModule } from '@nestjs/typeorm'; 2import { AuthService } from './auth.service'; 3import { AuthController } from './auth.controller'; 4import { User } from './entities/user.entity'; 5 6@Module({ 7 providers: [AuthService], 8 controllers: [AuthController], 9 imports: [TypeOrmModule.forFeature([User])], 10}) 11export class AuthModule {}

应用配置

实现注册功能