Skip to content

Commit

Permalink
[Implement][Authentication] Google Login for Customer
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiavohuynhdai authored and hideonbush106 committed Jan 27, 2024
1 parent c20cb3a commit 9cba8b0
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 48 deletions.
4 changes: 4 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ JWT_ACCESS_EXPIRATION=864000
JWT_REFRESH_SECRET=SWVG1ACUJwVfIyeBe8iGPugAIPq2dNshecqazIVqvK0zb6xJFGGGpoB8naJuOCatH4q+lE57L093HIBm9iZVCd8GfTGsXULaij0k4IU4SSQ/9yyp5qiTWJKnjsmfJc2/FX8xr6XL7chCX8tHgSye5clffIQIY0LlVCwUbC4CukZY8ScSs980EXqnwk63b6R4z+ULYdjPxMk5GQB/qHgJnpa3oFIdCirFtUQUaQY8JpLU6qArDN2LelAcg3g1Eilo4fDNMvDtjNtsRxWYt4zL8Gmf4Mt2lfrrfrKxShd8ITD/4z+zy0GS5Uxg3rD2iVj4E3kjrQv5CD8zhOOg5xA1NA==
JWT_REFRESH_EXPIRATION=90

# GOOGLE
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

CORS_VALID_ORIGINS=localhost,ngrok-free
172 changes: 168 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"google-auth-library": "^9.5.0",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"mongoose": "^8.1.0",
Expand Down
13 changes: 9 additions & 4 deletions src/auth/controllers/customer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common'
import { ApiBadRequestResponse, ApiBearerAuth, ApiBody, ApiOkResponse, ApiTags } from '@nestjs/swagger'
import { ErrorResponse, SuccessDataResponse } from '@common/contracts/dto'
import { LoginReqDto } from '@auth/dto/login.dto'
import { GoogleLoginReqDto, LoginReqDto } from '@auth/dto/login.dto'
import { AuthService } from '@auth/services/auth.service'
import { TokenResDto } from '@auth/dto/token.dto'
import { UserSide } from '@common/contracts/constant'
import { JwtAuthGuard } from '@auth/guards/jwt-auth.guard'
import { RegisterReqDto } from '@auth/dto/register.dto'
import { DataResponse } from '@src/common/contracts/openapi-builder'
import { DataResponse } from '@common/contracts/openapi-builder'

@ApiTags('Auth - Customer')
@Controller('customer')
Expand All @@ -19,9 +19,14 @@ export class AuthCustomerController {
@ApiOkResponse({ type: DataResponse(TokenResDto) })
@ApiBadRequestResponse({ type: ErrorResponse })
async login(@Body() loginReqDto: LoginReqDto): Promise<TokenResDto> {
const res = await this.authService.login(loginReqDto, UserSide.CUSTOMER)
return this.authService.login(loginReqDto, UserSide.CUSTOMER)
}

return res
@Post('google')
@ApiOkResponse({ type: DataResponse(TokenResDto) })
@ApiBadRequestResponse({ type: ErrorResponse })
async googleLogin(@Body() googleLoginReqDto: GoogleLoginReqDto): Promise<TokenResDto> {
return this.authService.googleLogin(googleLoginReqDto)
}

@Post('register')
Expand Down
6 changes: 6 additions & 0 deletions src/auth/dto/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export class LoginReqDto {
@IsNotEmpty()
password: string;
}

export class GoogleLoginReqDto {
@ApiProperty()
@IsNotEmpty()
token: string;
}
9 changes: 0 additions & 9 deletions src/auth/dto/register.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,4 @@ export class RegisterReqDto {
@IsNotEmpty()
@IsStrongPassword()
password: string

@ApiProperty()
@IsNotEmpty()
@Matches(PHONE_REGEX)
phone: string

@ApiProperty()
@IsNotEmpty()
address: string
}
Loading

0 comments on commit 9cba8b0

Please sign in to comment.