Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
import { createClientConfig, createUnauthenticatedClientConfig } from 'payload';
|
|
import { cache } from 'react';
|
|
let cachedClientConfigs = global._payload_clientConfigs;
|
|
if (!cachedClientConfigs) {
|
|
cachedClientConfigs = global._payload_clientConfigs = {};
|
|
}
|
|
export const getClientConfig = cache(({
|
|
config,
|
|
i18n,
|
|
importMap,
|
|
user
|
|
}) => {
|
|
const currentLanguage = i18n.language;
|
|
if (cachedClientConfigs[currentLanguage] && !global._payload_doNotCacheClientConfig) {
|
|
if (!user) {
|
|
return createUnauthenticatedClientConfig({
|
|
clientConfig: cachedClientConfigs[currentLanguage]
|
|
});
|
|
}
|
|
return cachedClientConfigs[currentLanguage];
|
|
}
|
|
const cachedClientConfig = createClientConfig({
|
|
config,
|
|
i18n,
|
|
importMap,
|
|
user
|
|
});
|
|
cachedClientConfigs[currentLanguage] = cachedClientConfig;
|
|
global._payload_clientConfigs = cachedClientConfigs;
|
|
global._payload_doNotCacheClientConfig = false;
|
|
if (!user) {
|
|
return createUnauthenticatedClientConfig({
|
|
clientConfig: cachedClientConfig
|
|
});
|
|
}
|
|
return cachedClientConfig;
|
|
});
|
|
//# sourceMappingURL=getClientConfig.js.map |