Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
How to name dexie db from localstorage item?

I'm using Dexie for my vue project and I'm trying to give Dexie DB a name depending on the user name logged in;

I'm following this logic:

  • Login component gets uid and save in local storage
  • in db.js the new Dexie() takes the name from localstorage

in login.vue

async function submit() {
  const q = query(
    collection(remoteDb, "customers"),
    where("email", "==", user.value.email)
  );

  const querySnapshot = await getDocs(q);
  querySnapshot.forEach((doc) => {
    if (doc.data().password === user.value.password) {
      localStorage.setItem("isLoggedIn", true);
      localStorage.setItem("username", doc.name);
      router.push({ name: "ChooseProfile" });
    } else {
      $q.notify({ message: "incorrect password" });
    }
  });
}

in db.js

const db = new Dexie(`LocalDB-${localStorage.getItem("username")}`);

But every time Dexie creates a DB called LocalDB-null, like if it's creating the DB before the localstorage item is saved. I guess Dexie is creating a new DB even when DB is not imported in the component yet.

How to make it wait until the localstorage.getItem("username") !== null to create the db ?

thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!