-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
createRxDatabase(): A RxDatabase with the same name and adapter already exists. #5924
Comments
You have to either cache the RxDatabase instance or call |
I tried destroying the database instance: let currentUser = null;
export const recreateDBPromise = async () => {
const newUser = localStorage.getItem('userId');
if (newUser !== currentUser) {
if (database) {
await database.destroy();
}
database = await _create(newUser);
currentUser = newUser;
}
return database;
};
export const get = async () => {
console.log('Current user:', currentUser);
return await recreateDBPromise();
}; This results in Screen.Recording.2024-04-21.at.11.22.50.AM.mov |
Please make a PR with a test case. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem. Notice that only bugs in the rxdb premium plugins are ensured to be fixed by the maintainer. Everything else is expected to be fixed by the community, likely you must fix it by yourself. |
Issues are autoclosed after some time. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem. |
I am trying to create separate databases for each
userId
. The idea is to segregate the data for each user. In the code below you can see that if thecurrentUser
has changed, we return pertaining db instance.Here you can see we have a button that toggles between user ids. These user ids are stored in the
localStorage
and referred when creating db instances as shown above. Also, whenuserId
is changed I also intend to navigate to the home screen which I have managed to mimic usingreact-router-dom
useNavigate
function.Note: These approaches here are all contrived. I have tried simplify this example as much as possible to make a point. However, the issue does exists in the full blown app where I am trying to switch between google oauth users and navigate from the signin page to the home page.
Screen.Recording.2024-04-20.at.11.31.42.PM.mov
The problem that I face here is that despite application storage having separate dbs for both the user ids. Switching between user ids fails to fetch data.
Not sure if this is bug or it is something that I am doing wrong?
Screen.Recording.2024-04-20.at.11.32.49.PM.mov
Although I would like to point out that reloading the whole page using
window.location.reload();
while navigating avoids this issue!I have created a Pr to my fork so that it is easier to see the changes that were made to reproduce this issue: https://github.com/iamsmkr/rxdb/pull/1/files
The text was updated successfully, but these errors were encountered: