Skip to content
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

custom storage option #146

Open
ericuldall opened this issue Sep 7, 2023 · 3 comments
Open

custom storage option #146

ericuldall opened this issue Sep 7, 2023 · 3 comments

Comments

@ericuldall
Copy link

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
Copy link
Author

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
Copy link
Owner

Yep. I think you can do the following in a PR:

  1. Make your own replacement utilities for the localstorage plugin found here: https://github.com/marshallswain/feathers-pinia/tree/main/src/localstorage
  2. Add clearStorage and storagePlugin options to the PiniaClientConfig: https://github.com/marshallswain/feathers-pinia/blob/main/src/create-pinia-client.ts#L35
  3. 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
  4. 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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants