Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Request scope to UserLoader and UserValidator object #14

Open
prakash290 opened this issue Sep 13, 2020 · 0 comments
Open

Support Request scope to UserLoader and UserValidator object #14

prakash290 opened this issue Sep 13, 2020 · 0 comments

Comments

@prakash290
Copy link

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.

@prakash290 prakash290 changed the title Request scope to UserLoader and UserValidator object Support Request scope to UserLoader and UserValidator object Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant