Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public log(message: any, context?: string) {
if (this.isValidLevel(ELogLevel.debug)) {
Logger.log(JSON.stringify(message, null, 2), context || this._context);
}
}
// tslint:disable-next-line: no-any
handle(event: UserDeletedEvent) {
Logger.log(event, 'UserDeletedEvent'); // write here
}
}
async execute(command: DeleteUserCommand, resolve: (value?) => void) {
Logger.log('Async DeleteUserHandler...', 'DeleteUserCommand');
const {userDto} = command;
const user = this.publisher.mergeObjectContext(
await this.repository.deleteUser(userDto),
);
user.commit();
resolve();
}
}
uploadCat(
@UploadedFile()
file: UploadedFileMetadata,
) {
Logger.log(
`File "${file.originalname}" was uploaded using Azure Storage Interceptor`,
'CatController',
);
return this.addCat(file.storageUrl);
}
async changeEmail(token: string): Promise {
const emailChange = await this.emailChangeRepository.findOne(token);
if (emailChange && emailChange.validUntil > new Date()) {
const userEntity = await this.userService.getUserEntityById(
emailChange.userId,
);
userEntity.email = emailChange.newEmail;
await this.userService.updateUser(userEntity);
await this.emailChangeRepository.delete(emailChange);
} else {
Logger.log(`Invalid email change token ${token} is rejected.`);
throw new NotFoundException();
}
}
handle(event: TenantRemovedEvent): any {
Logger.log(event, 'TenantRemovedEvent');
}
}
public async validateUser(input: LoginInput): Promise {
try {
return await this.loginCmd(input);
} catch (e) {
Logger.log(e, 'ValidateUser');
throw new AuthenticationError(e.message);
}
}
}
handle(event: UserLoggedInEvent): any {
Logger.log(event, 'UserLoggedInHandler');
}
}
async facebookSignIn(code: string, host?: string): Promise {
const queryParams: string[] = [
`client_id=${this.fbConfig.client_id}`,
`redirect_uri=${this.fbConfig.oauth_redirect_uri}`,
`client_secret=${this.fbConfig.client_secret}`,
`code=${code}`
];
const uri: string = `${this.fbConfig.access_token_uri}?${queryParams.join(
'&'
)}`.replace('{host}', host);
Logger.log(uri, AuthService.name + ':facebookSignIn');
try {
const response = await this.httpService
.get(uri)
.pipe(map(res => res.data))
.toPromise();
if (response.error) {
Logger.error(JSON.stringify(response), undefined, AuthService.name);
throw new BadRequestException(response.error.message);
}
const access_token = response.access_token;
const uriToken = `${this.localUri}/api/auth/facebook/token`;
const profileResponse = await this.httpService
.post(uriToken, stringify({ access_token }), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.pipe(map(res => res.data))
static initEnvironment(rootPath: string, env: string = process.env.NODE_ENV || 'development') {
const envPath = path.resolve(rootPath, !env ? '.env' : `.env.${env}`);
dotenv({ path: envPath });
Logger.log(`Loading environment variables from ${envPath}`, ConfigModule.name);
}