Skip to content

Commit

Permalink
feat: decryption of password (#207)
Browse files Browse the repository at this point in the history
Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 11, 2024
1 parent 84dc177 commit 3e7846a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
33 changes: 4 additions & 29 deletions apps/api-gateway/src/authz/authz.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BadRequestException,
Body,
Controller,
Get,
Expand Down Expand Up @@ -83,37 +82,17 @@ export class AuthzController {
@Post('/signup')
@ApiOperation({ summary: 'Register new user to platform', description: 'Register new user to platform' })
async addUserDetails(@Body() userInfo: AddUserDetails, @Res() res: Response): Promise<Response> {
let finalResponse;
let userDetails;

if (false === userInfo.isPasskey) {

const decryptedPassword = this.commonService.decryptPassword(userInfo.password);
if (8 <= decryptedPassword.length && 50 >= decryptedPassword.length) {
this.commonService.passwordValidation(decryptedPassword);
userInfo.password = decryptedPassword;
userDetails = await this.authzService.addUserDetails(userInfo);
finalResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.user.success.create,
data: userDetails.response
};
} else {
throw new BadRequestException('Password name must be between 8 to 50 Characters');
}
} else {

userDetails = await this.authzService.addUserDetails(userInfo);
finalResponse = {
const userDetails = await this.authzService.addUserDetails(userInfo);
const finalResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.user.success.create,
data: userDetails.response
};
}
return res.status(HttpStatus.CREATED).json(finalResponse);

}


/**
*
* @param loginUserDto
Expand All @@ -130,11 +109,7 @@ export class AuthzController {
async login(@Body() loginUserDto: LoginUserDto, @Res() res: Response): Promise<Response> {

if (loginUserDto.email) {
let decryptedPassword;
if (loginUserDto.password) {
decryptedPassword = this.commonService.decryptPassword(loginUserDto.password);
}
const userData = await this.authzService.login(loginUserDto.email, decryptedPassword, loginUserDto.isPasskey);
const userData = await this.authzService.login(loginUserDto.email, loginUserDto.password, loginUserDto.isPasskey);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.login,
Expand Down
17 changes: 11 additions & 6 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class UserService {
const resUser = await this.userRepository.addUserPassword(email, userInfo.password);
const userDetails = await this.userRepository.getUserDetails(email);
const decryptedPassword = await this.commonService.decryptPassword(userDetails.password);

if (!resUser) {
throw new NotFoundException(ResponseMessages.user.error.invalidEmail);
}
Expand All @@ -269,9 +270,11 @@ export class UserService {
password: decryptedPassword
});
} else {
const decryptedPassword = await this.commonService.decryptPassword(userInfo.password);

supaUser = await this.supabaseService.getClient().auth.signUp({
email,
password: userInfo.password
password: decryptedPassword
});
}

Expand Down Expand Up @@ -345,9 +348,10 @@ export class UserService {
const getUserDetails = await this.userRepository.getUserDetails(userData.email);
const decryptedPassword = await this.commonService.decryptPassword(getUserDetails.password);
return this.generateToken(email, decryptedPassword);
} else {
const decryptedPassword = await this.commonService.decryptPassword(password);
return this.generateToken(email, decryptedPassword);
}

return this.generateToken(email, password);
} catch (error) {
this.logger.error(`In Login User : ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
Expand All @@ -356,14 +360,15 @@ export class UserService {

async generateToken(email: string, password: string): Promise<object> {
try {
const supaInstance = await this.supabaseService.getClient();

const supaInstance = await this.supabaseService.getClient();
this.logger.error(`supaInstance::`, supaInstance);

const { data, error } = await supaInstance.auth.signInWithPassword({
email,
password
});
});

this.logger.error(`Supa Login Error::`, JSON.stringify(error));

if (error) {
Expand Down

0 comments on commit 3e7846a

Please sign in to comment.