nestjs

NestJS jwt-passport Authentication

家住魔仙堡 提交于 2020-07-06 20:26:10
问题 I want to implement a distributable authentication library to use it on several of my projects. The library should implement JWT authentication method. The code is as follows: jwt.strategy.ts: import {ExtractJwt, Strategy} from 'passport-jwt'; import {PassportStrategy} from '@nestjs/passport'; import {Injectable} from '@nestjs/common'; import {JwtPayload, User} from './interfaces'; import {ConfigService} from "./config.service"; @Injectable() export class JwtStrategy extends PassportStrategy

How to log all Axios external http requests in NestJS

霸气de小男生 提交于 2020-06-29 06:08:10
问题 I want to be able to log each axios request with full url, headers, etc but currently didn't find a way to do so. What I did achieve so far is to writhe an Http Interceptor based on this answer export class HttpLoggerInterceptor implements NestInterceptor { intercept( context: ExecutionContext, call$: Observable<any>, ): Observable<any> { return call$.pipe( map(data => { // pipe call to add / modify header(s) after remote method const req = context.switchToHttp().getRequest(); return data; })

Unable to inject Request into a class in nestjs

落花浮王杯 提交于 2020-06-28 05:36:58
问题 The class I want to inject the request into looks as follows: @ValidatorConstraint({ name: 'isUniqueEntryTitle', async: true }) @Injectable({ scope: Scope.REQUEST }) export class IsUniqueEntryTitle implements ValidatorConstraintInterface { constructor( private readonly userService: UserService, @Inject(REQUEST) private request: Request, ) {} public async validate(val: any, args: ValidationArguments): Promise<boolean> { console.log('Request', this.request); return true; } public defaultMessage

How to format response before sending in Nest.js?

限于喜欢 提交于 2020-06-23 14:52:13
问题 I followed the documentation and was able to add an interceptor for response mapping. I want a consistent json format output for responses. How can I achieve this with interceptor or with something else better than this approach. { "statusCode": 201, "message": "Custom Dynamic Message" "data": { // properties meta: {} } } transform.interceptor.ts import { Injectable, NestInterceptor, ExecutionContext, CallHandler, } from '@nestjs/common'; import { Observable } from 'rxjs'; import { map } from

Can't figure out how to update embedded entity in typeorn

六眼飞鱼酱① 提交于 2020-06-23 14:07:13
问题 I have a category entity CategoryEntity and each such a category can have subcategories (one level depth), the corresponding entity is called SubcategoryEntity , the relation between the entities is OneToMany . A user needs to be able to create subcategories in all the available categories. As far as I understand, I ought to learn how to update category's subcategories. This is my try, but obviously it does not do what I'd like it to... public async createSubcategoryByUserId(userId: number,

Can't figure out how to update embedded entity in typeorn

こ雲淡風輕ζ 提交于 2020-06-23 14:07:12
问题 I have a category entity CategoryEntity and each such a category can have subcategories (one level depth), the corresponding entity is called SubcategoryEntity , the relation between the entities is OneToMany . A user needs to be able to create subcategories in all the available categories. As far as I understand, I ought to learn how to update category's subcategories. This is my try, but obviously it does not do what I'd like it to... public async createSubcategoryByUserId(userId: number,

Cannot read property 'create' of undefined in TS

隐身守侯 提交于 2020-06-23 14:03:55
问题 I create an function to create new user in NestJS/TypeScript, after launch my function, my console throw me this: TypeError: Cannot read property 'create' of undefined at Repository.create (/mnt/c/Users/Maciek/Desktop/personal-data/node_modules/typeorm/repository/Repository.js:49:29) at UserService.create (/mnt/c/Users/Maciek/Desktop/personal-data/dist/user/user.service.js:60:40) at AuthController.register (/mnt/c/Users/Maciek/Desktop/personal-data/dist/auth/auth.controller.js:38:45) can

Cannot read property 'create' of undefined in TS

天涯浪子 提交于 2020-06-23 14:00:08
问题 I create an function to create new user in NestJS/TypeScript, after launch my function, my console throw me this: TypeError: Cannot read property 'create' of undefined at Repository.create (/mnt/c/Users/Maciek/Desktop/personal-data/node_modules/typeorm/repository/Repository.js:49:29) at UserService.create (/mnt/c/Users/Maciek/Desktop/personal-data/dist/user/user.service.js:60:40) at AuthController.register (/mnt/c/Users/Maciek/Desktop/personal-data/dist/auth/auth.controller.js:38:45) can

NestJS : database connection (TypeORM) by request (subdomain)

て烟熏妆下的殇ゞ 提交于 2020-06-22 09:06:21
问题 I'm trying to build a SAAS product over Nest/TypeORM and I need to configure/change database connection by subdomain. customer1.domain.com => connect to customer1 database customer2.domain.com => connect to customer2 database x.domain.com => connect to x database How can I do that ? With interceptors or request-context (or Zone.js) ? I don't know how to start. Is someone already do that ? WIP : what I am currently doing : add all connections settings into ormconfig file create Middleware on

NestJS : database connection (TypeORM) by request (subdomain)

血红的双手。 提交于 2020-06-22 09:05:46
问题 I'm trying to build a SAAS product over Nest/TypeORM and I need to configure/change database connection by subdomain. customer1.domain.com => connect to customer1 database customer2.domain.com => connect to customer2 database x.domain.com => connect to x database How can I do that ? With interceptors or request-context (or Zone.js) ? I don't know how to start. Is someone already do that ? WIP : what I am currently doing : add all connections settings into ormconfig file create Middleware on