From 8b6666534e09d7d1daeaca2199b942263a7a6ecd Mon Sep 17 00:00:00 2001 From: vinod <31404750+vinodnextcoder@users.noreply.github.com> Date: Fri, 5 Jan 2024 23:40:48 +0530 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a633190..c31c0cb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![Prettier](https://img.shields.io/badge/Code%20style-prettier-informational?logo=prettier&logoColor=white) [![GPL v3 License](https://img.shields.io/badge/License-GPLv3-green.svg)](./LICENSE) -[![HitCount](https://hits.dwyl.com/anilahir/nestjs-authentication-and-authorization.svg)](https://hits.dwyl.com/vinodnextcoder/nestjs-jwt-auth-cookie-mongoose) +[![HitCount](https://hits.dwyl.com/vinodnextcoder/nestjs-jwt-auth-cookie-mongoose.svg)](https://hits.dwyl.com/vinodnextcoder/nestjs-jwt-auth-cookie-mongoose) ## Description From 8d5ef58e60b815d418fe1411e39819f46ccd44ad Mon Sep 17 00:00:00 2001 From: Pankaj Gurav Date: Wed, 7 Feb 2024 11:48:58 +0530 Subject: [PATCH 2/2] To send error for wrong password --- .env.development | 2 +- src/auth/auth.controller.ts | 2 ++ src/auth/auth.service.ts | 4 ++++ src/users/users.controller.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index 09d9bdf..3114ae8 100644 --- a/.env.development +++ b/.env.development @@ -3,5 +3,5 @@ MONGODB_URI=mongodb://0.0.0.0:27017/test SERVER_URL=http://localhost:3000/ PORT=4000 JWT_KEY='MXvTnOhWYMYgYiFnBFRfX4Fnd4ZkXLK8qYU' -IS_COOKIE_AUTH=true +IS_COOKIE_AUTH=false IS_EMAIL=false diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 762b46e..6c01f35 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -61,6 +61,8 @@ export class AuthController { signInDto.password ); console.log(token) + console.log(signInDto.email, + signInDto.password) res.cookie("access_token", token.access_token, { httpOnly: true, diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 879b122..ca4e364 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -20,17 +20,21 @@ export class AuthService { const id: string = uuid(); this.logger.log('auth service api called', id, 'auth.service.ts', '', '', 'signIn-service'); const user = await this.usersService.findOneUser(email); + console.log(user) if (!user) { throw new UnauthorizedException('Username and password wrong.'); } const match = await bcrypt.compare(pass, user?.password); + console.log(match) if (match) { const payload = { email: user.email, userId: user._id.toString(), username: user.username }; const tokens = await this.getTokens(payload); return { ...tokens }; + } else { + throw new UnauthorizedException('Username and password wrong.'); } } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index d7e8fea..4fb4bf0 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -106,6 +106,7 @@ export class UserController { @UseFilters(new HttpExceptionFilter()) async findUser(@Query('userid') name: string, @Req() req: UserRequest, @Res() res: Response): Promise { const id: string = uuid(); + console.log('=============================================================IN FUNCTION') this.logger.log('find User api called', id, 'users.controler.ts', 'GET', '/getuser', 'findUser'); let userid: string = null;