Datasource Switcher #7173
Replies: 4 comments
-
Conceptually before going toward any solution, this sounds like a bad idea to even contemplate. First off, how are you storing the passwords assuming they constitute part of the login? If the passwords are stored without hashing them you've created a vulnerability by design(if your initial database is compromised, then all are). If you do hash the passwords, how do you propose to use them to login? Also probably best to ask questions like this on stackoverflow.com and tag as loopback. |
Beta Was this translation helpful? Give feedback.
-
I have same pb i would update name database dynamically if user1 is logged wil be get data from db1 I tried to update in |
Beta Was this translation helpful? Give feedback.
-
@sbacem same as your situation here. |
Beta Was this translation helpful? Give feedback.
-
See this example on how to deal with multi-tenancy. IMO it's not a good idea to be switching between datasources as this makes for a rather fragile system with many moving parts. There's a lot of potential pitfalls that may arise as a result. My advise for new projects that have structured data would be to design a properly normalised SQL database, which won't require any datasource switching. |
Beta Was this translation helpful? Give feedback.
-
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
Appreciate the guidance!
Beta Was this translation helpful? Give feedback.
All reactions