I am trying to setup unstorage with localstorage driver but haven't had luck getting it to work. I amusing Pinia for state management and I am connecting to a Laravel sanctum SPA backend. While that works, I need to store a key sent from the back in the session storage that I am checking between navigation whether the user is still logged in. My unstorage setup is like below:
import { createStorage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
// import indexedDbDriver from "unstorage/drivers/indexedb";
const storage = createStorage<string | number>({
driver: localStorageDriver({ base: 'leads:', }),
});
async function hasItem(key: string) {
return await storage.hasItem(key)
}
async function addItem(item: string | number) {
await storage.setItem('token', item)
}
async function fetchItem(key: string) {
return await storage.getItem(key)
}
async function deleteItem(key: string) {
await storage.removeItem(key, { removeMeta: true })
}
async function deleteAll() {
await storage.clear()
}
async function startWatch(key: string) {
await storage.watch((event, key) => {
console.log(key);
})
}
async function stopWatch() {
await storage.unwatch();
}
export default storage;
export { addItem, deleteAll, deleteItem, fetchItem, hasItem, startWatch, stopWatch };
And then in the pinia store I access them via the functions I have created. The problem is that I am getting a [unstorage] [localstorage] Missing required option localStorage. error no matter what I do. Is is a bug in Nuxt or I am doing something wrong?