@@ -53,27 +53,32 @@ const prepareNewCookieString = (apiState, newStoreCode) => {
5353 return cookie ;
5454} ;
5555
56- export default async ( { app } ) => {
57- const { i18n } = app ;
58- const currentStoreCode = readStoreCookie ( app ) ;
56+ export default ( { app } ) => {
57+ app . $vsf . $magento . client . interceptors . request . use ( async ( request ) => {
5958
60- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
61- if ( ! currentStoreCode || ! findLocaleBasedOnStoreCode ( currentStoreCode , i18n . locales ) ) {
62- await setDefaultLocale ( i18n ) ;
59+ const { i18n } = app ;
60+ const currentStoreCode = readStoreCookie ( app ) ;
6361
64- return ;
65- }
62+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
63+ if ( ! currentStoreCode || ! findLocaleBasedOnStoreCode ( currentStoreCode , i18n . locales ) ) {
64+ await setDefaultLocale ( i18n ) ;
6665
67- const i18nCurrentLocaleCode = i18n . locale ;
68- const localeCookie = app . $cookies . get ( cookieNames . localeCookieName ) ;
66+ return ;
67+ }
6968
70- if ( i18nCurrentLocaleCode !== localeCookie ) {
71- const apiState = app . $vsf . $magento . config . state ;
69+ const i18nCurrentLocaleCode = i18n . locale ;
70+ const localeCookie = app . $cookies . get ( cookieNames . localeCookieName ) ;
7271
73- apiState . setStore ( i18nCurrentLocaleCode ) ;
74- apiState . setLocale ( i18nCurrentLocaleCode ) ;
72+ if ( i18nCurrentLocaleCode !== localeCookie ) {
73+ const apiState = app . $vsf . $magento . config . state ;
7574
76- // eslint-disable-next-line no-param-reassign
77- app . $vsf . $magento . config . axios . headers . cookie = prepareNewCookieString ( apiState , i18nCurrentLocaleCode ) ;
78- }
75+ apiState . setStore ( i18nCurrentLocaleCode ) ;
76+ apiState . setLocale ( i18nCurrentLocaleCode ) ;
77+
78+ // eslint-disable-next-line no-param-reassign
79+ request . headers . cookie = prepareNewCookieString ( apiState , i18nCurrentLocaleCode ) ;
80+ }
81+
82+ return request ;
83+ } ) ;
7984} ;
0 commit comments