chore(): js-sdk set locale in server environment (#14313)
**What** Prevent guess work in server environment and warn user when they try to set the locale on the sdk
This commit is contained in:
committed by
GitHub
parent
accb778039
commit
191e647eec
@@ -147,9 +147,17 @@ export class Client {
|
||||
}
|
||||
|
||||
setLocale(locale: string) {
|
||||
if (!window) {
|
||||
this.logger.warn(
|
||||
"setLocale is not available in the server environment. Please set the locale directly through the 'x-medusa-locale' header."
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (hasStorage("localStorage")) {
|
||||
window.localStorage.setItem(LOCALE_STORAGE_KEY, locale)
|
||||
}
|
||||
|
||||
this.locale_ = locale
|
||||
}
|
||||
|
||||
@@ -249,6 +257,11 @@ export class Client {
|
||||
return async (input: FetchInput, init?: FetchArgs) => {
|
||||
// We always want to fetch the up-to-date JWT token before firing off a request.
|
||||
const headers = new Headers(defaultHeaders)
|
||||
|
||||
if (this.locale) {
|
||||
headers.set("x-medusa-locale", this.locale)
|
||||
}
|
||||
|
||||
const customHeaders = {
|
||||
"x-medusa-locale": this.locale,
|
||||
...this.config.globalHeaders,
|
||||
|
||||
Reference in New Issue
Block a user