You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our application is developed with multiple tenant and multiple database. Based on request we determine which database connection should be establish. we can able to achieve this using nest js Request Scope. So the same thing how to achieve for UserLoader and UserValidator.
database : PostgreSQL
Client : Client A, Client B, Client C
Each client can have separate database but entity structure is same. I want to validate user based on client type which will come through the request header.
TenancyModule : which provides database connection based on request header.
import { Global, Module, Scope } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { getConnection } from 'typeorm';
I want UserLoader to support request scope so that I can get request information based on this I can able to validate User.
The text was updated successfully, but these errors were encountered:
prakash290
changed the title
Request scope to UserLoader and UserValidator object
Support Request scope to UserLoader and UserValidator object
Sep 13, 2020
Our application is developed with multiple tenant and multiple database. Based on request we determine which database connection should be establish. we can able to achieve this using nest js Request Scope. So the same thing how to achieve for UserLoader and UserValidator.
database : PostgreSQL
Client : Client A, Client B, Client C
Each client can have separate database but entity structure is same. I want to validate user based on client type which will come through the request header.
TenancyModule : which provides database connection based on request header.
import { Global, Module, Scope } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { getConnection } from 'typeorm';
const connectionFactory = {
provide: 'CONNECTION',
scope: Scope.REQUEST,
useFactory: (req) => {
const tenant = getConnection(req.headers.client);
return getConnection(tenant);
},
inject: [REQUEST],
};
@global()
@module({
providers: [connectionFactory],
exports: ['CONNECTION'],
})
export class TenancyModule {}
User Service class:
@Injectable({scope: Scope.REQUEST})
export class UserService {
private readonly userRepository: Repository;
constructor(@Inject('CONNECTION') connection) {
this.userRepository = connection.getRepository(User);
}
I want UserLoader to support request scope so that I can get request information based on this I can able to validate User.
The text was updated successfully, but these errors were encountered: