How to access localStorage in filter JS files like vue-storefront/core/filters/price.js

Hello there,

We want to access user option selection from Browser in price.js filter file (vue-storefront/core/filters/price.js).
User will select desired currency from currency-dropdown & we will modify price according to selected currency.

User selection is stored in localStorage.
In price.js, using Async function for accessing “localStorage” gives response as Promise Array whose values are not usable in code, similar to issue discussed here

Application stops working if not using Async function.


Hello. Could you please share with us code snippets with your changes?

Hi @Fifciuu,

Thanks for the reply.
Please check attached image where line of code causing application not working highlighted in red box.

Our ultimate requirement is to access user option selection from browser in price.js filter file.


@anupwankhede What error do you get? You need to wrap this in !isServer because you can’t access localstorage on server side.

let localCurrencyRate = '1'
if (!isServer) {
  localCurrencyRate = localStorage.getItem()

Hi @gibkigonzo,

Thanks for your advise.
It worked as desired.

Thanks a lot mate!!!