custom storage option
ericuldall opened this issue · 3 comments
ericuldall commented
I use feathers pinia in a chrome extension and would be great if I could sync with chrome.storage.sync or chrome.storage.local which does not conform to the standard browser Storage {} interface.
Is there a way to do this in v3?
ericuldall commented
Just for an example, I have to do all sorts of trickery to get auth working:
const authStore = useAuthStore();
chrome.storage.onChanged.addListener(async (changes, area) => {
if (area == 'local' && changes['feathers-jwt']) {
await authStore.authenticate({
strategy: "jwt",
accessToken: changes['feathers-jwt'].newValue
})
router.push('/');
}
});
(async () => {
let token;
if (chrome?.storage?.local) {
token = await chrome.storage.local.get(['feathers-jwt']);
}
let preAuth;
if (token?.['feathers-jwt']) {
preAuth = authStore.authenticate({
strategy: "jwt",
accessToken: token['feathers-jwt']
})
} else {
preAuth = Promise.resolve();
}
await preAuth.catch((e) => {});
app.mount('#app')
})();
If feather-pinia already understood how to work with chrome.storage I could probably cut out a lot of this hacky stuff.
marshallswain commented
Yep. I think you can do the following in a PR:
- Make your own replacement utilities for the localstorage plugin found here: https://github.com/marshallswain/feathers-pinia/tree/main/src/localstorage
- Add
clearStorage
andstoragePlugin
options to the PiniaClientConfig: https://github.com/marshallswain/feathers-pinia/blob/main/src/create-pinia-client.ts#L35 - If the
options.storagePlugin
is provided, use it instead of__sync
here: https://github.com/marshallswain/feathers-pinia/blob/main/src/create-pinia-client.ts#L137C9-L137C15 - If
options.clearStorage
is provided, use it here: https://github.com/marshallswain/feathers-pinia/blob/main/src/create-pinia-client.ts#L176
I think that should do the trick.
ericuldall commented
I've started a draft PR here: https://github.com/marshallswain/feathers-pinia/pull/147/files
Any comments are appreciated. I'll be testing and updating this week.