diff --git a/apps/backend/src/auth/auth.controller.ts b/apps/backend/src/auth/auth.controller.ts index aab1384..4cdc878 100644 --- a/apps/backend/src/auth/auth.controller.ts +++ b/apps/backend/src/auth/auth.controller.ts @@ -48,16 +48,18 @@ export class AuthController { // TODO will be deprecated if we use Google OAuth @Post('/verify') - verifyUser(@Body() body: VerifyUserRequestDTO): void { - try { - this.authService.verifyUser(body.email, String(body.verificationCode)); - } catch (e) { - throw new BadRequestException(e.message); - } + async verifyUser(@Body() body: VerifyUserRequestDTO) { + return this.authService + .verifyUser(body.email, String(body.verificationCode)) + .catch((err) => { + throw new BadRequestException(err.message); + }); } @Post('/signin') - signin(@Body() signInDto: SignInRequestDto): Promise { + async signin( + @Body() signInDto: SignInRequestDto, + ): Promise { return this.authService.signin(signInDto).catch((err) => { throw new UnauthorizedException(err.message); }); diff --git a/apps/backend/src/auth/auth.service.ts b/apps/backend/src/auth/auth.service.ts index 2f3036e..299e052 100644 --- a/apps/backend/src/auth/auth.service.ts +++ b/apps/backend/src/auth/auth.service.ts @@ -82,16 +82,22 @@ export class AuthService { verifyUser(email: string, verificationCode: string): Promise { return new Promise((resolve, reject) => { - return new CognitoUser({ + const cognitoUser = new CognitoUser({ Username: email, Pool: this.userPool, - }).confirmRegistration(verificationCode, true, (err, result) => { - if (err) { - reject(err); - } else { - resolve(result); - } }); + + return cognitoUser.confirmRegistration( + verificationCode, + true, + (err, result) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); }); } @@ -108,7 +114,7 @@ export class AuthService { const cognitoUser = new CognitoUser(userData); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { return cognitoUser.authenticateUser(authenticationDetails, { onSuccess: (result) => { resolve({ @@ -117,7 +123,6 @@ export class AuthService { }); }, onFailure: (err) => { - console.log(err); reject(err); }, }); diff --git a/apps/backend/src/auth/dtos/verify-user.request.dto.ts b/apps/backend/src/auth/dtos/verify-user.request.dto.ts index dd695d3..5ea5c3f 100644 --- a/apps/backend/src/auth/dtos/verify-user.request.dto.ts +++ b/apps/backend/src/auth/dtos/verify-user.request.dto.ts @@ -1,9 +1,9 @@ -import { IsEmail, IsNumber } from 'class-validator'; +import { IsEmail, IsNumberString } from 'class-validator'; export class VerifyUserRequestDTO { @IsEmail() email: string; - @IsNumber() + @IsNumberString() verificationCode: number; }