diff --git a/content/security/authentication.md b/content/security/authentication.md index 2c19d246dc..8ff2df290c 100644 --- a/content/security/authentication.md +++ b/content/security/authentication.md @@ -29,8 +29,11 @@ Replace the default contents of these generated files as shown below. For our sa @@filename(users/users.service) import { Injectable } from '@nestjs/common'; -// This should be a real class/interface representing a user entity -export type User = any; +export interface User { + userId: number; + username: string; + password: string; +} @Injectable() export class UsersService { @@ -48,7 +51,7 @@ export class UsersService { ]; async findOne(username: string): Promise { - return this.users.find(user => user.username === username); + return this.users.find((user) => user.username === username); } } @@switch @@ -72,7 +75,7 @@ export class UsersService { } async findOne(username) { - return this.users.find(user => user.username === username); + return this.users.find((user) => user.username === username); } } ``` @@ -184,6 +187,7 @@ With this in place, let's open up the `AuthController` and add a `signIn()` meth ```typescript @@filename(auth/auth.controller) import { Body, Controller, Post, HttpCode, HttpStatus } from '@nestjs/common'; +import { User } from '../users/users.service'; import { AuthService } from './auth.service'; @Controller('auth') @@ -192,13 +196,13 @@ export class AuthController { @HttpCode(HttpStatus.OK) @Post('login') - signIn(@Body() signInDto: Record) { + signIn(@Body() signInDto: Pick) { return this.authService.signIn(signInDto.username, signInDto.password); } } ``` -> info **Hint** Ideally, instead of using the `Record` type, we should use a DTO class to define the shape of the request body. See the [validation](/techniques/validation) chapter for more information. +> info **Hint** Ideally, instead of using the `Pick` type, we should use a DTO class to define the shape of the request body. See the [validation](/techniques/validation) chapter for more information.