Skip to content

Commit

Permalink
fix: resolves build error due to no REDIS_URL defined for storybook env
Browse files Browse the repository at this point in the history
- adds STORYBOOK_IS_STORYBOOK env var to prevent REDIS usage in storybook
  • Loading branch information
mohitb35 committed Apr 11, 2024
1 parent 4895e73 commit 9ea7417
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ module.exports = {
docs: {
autodocs: true,
},

env: (config) => ({
...config,
STORYBOOK_IS_STORYBOOK: true,
}),
};
4 changes: 4 additions & 0 deletions src/redis-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createClient } from '@vercel/kv';

const getRedisClient = () => {
if (process.env.STORYBOOK_IS_STORYBOOK) {
return null;
}

if (!process.env.REDIS_URL) {
throw new Error('REDIS_URL is not defined');
}
Expand Down
3 changes: 3 additions & 0 deletions src/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const getGlobalStyles = async () => {
const fetchConfig = async () => {
try {
let tenantConfig;
if (process.env.STORYBOOK_IS_STORYBOOK) {
return null;
}
if (typeof window !== 'undefined') {
// Check if tenantConfig is stored in local storage
const storedConfig = localStorage.getItem('tenantConfig');
Expand Down
10 changes: 6 additions & 4 deletions src/utils/multiTenancy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const getTenantConfig = async (slug: string): Promise<Tenant> => {
'env_missing';
const caching_key = `${cachingKeyPrefix}_TENANT_CONFIG_${slug}`;

const tenant = await redisClient.get<Tenant>(caching_key);
const tenant =
redisClient !== null ? await redisClient.get<Tenant>(caching_key) : null;

if (tenant) {
return tenant;
Expand All @@ -75,9 +76,10 @@ export const getTenantConfig = async (slug: string): Promise<Tenant> => {

const tenantConf = _tenantConf ?? defaultTenantConfig;

await redisClient.set(caching_key, JSON.stringify(tenantConf), {
ex: FIVE_HOURS,
});
redisClient !== null &&
(await redisClient.set(caching_key, JSON.stringify(tenantConf), {
ex: FIVE_HOURS,
}));

return tenantConf as Tenant; // Ensure that the returned value is of type Tenant
} catch (err) {
Expand Down

0 comments on commit 9ea7417

Please sign in to comment.