-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
I have First a global DataBase contain societyName and their databaseNames, each society have his databaseName,
when user want to login, first we check from the societyName, in the global DataBase, the databaseName, after that he connect with his Email and password stored in his selected database.
So I'm wanting to know, after i have the databaseName of this user, how to switch from global database to the database according to the databaseName of this user.
My idea, in db.datasources.ts, instead of having a fixed datasource from client-db.datasource.json, I try to recover the datasource dynamically according to the current-user, but it does not go well, the database does not change.
my code
import {inject} from '@loopback/core';
import {juggler } from '@loopback/repository';
//import * as config from './client-db.datasource.json'
import { binderService } from '../services/binder-service';
export class ClientDbDataSource extends juggler.DataSource {
static dataSourceName = 'clientDb';
constructor(
@inject('datasources.config.clientDb', {optional: true})
dsConfig: object = binderService.getUserDataSource(), // getUserDataSource() return the datasource of the user from a controller "who-i-am"
) {
super(dsConfig);
}
}
Appreciate the guidance!
sbacemdougal83
Metadata
Metadata
Assignees
Labels
No labels