Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-ways-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/shared": patch
---

Use shared safe environment variable access in Netlify cache handler
9 changes: 6 additions & 3 deletions packages/shared/src/netlifyCacheHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { getEnvVariable } from './getEnvVariable';
import { isDevelopmentFromPublishableKey } from './keys';

/**
Expand All @@ -19,7 +19,7 @@ export const CLERK_NETLIFY_CACHE_BUST_PARAM = '__clerk_netlify_cache_bust';
* The issue happens only on Clerk development instances running on Netlify. This is
* a workaround until we find a better solution.
*
* See https://answers.netlify.com/t/cache-handling-recommendation-for-authentication-handshake-redirects/143969/1
* See https://answers.netlify.com/t/cache-handling-recommendation-for-authentication-handshake-redirects/143969/1.
*
* @internal
*/
Expand All @@ -33,7 +33,10 @@ export function handleNetlifyCacheInDevInstance({
publishableKey: string;
}) {
const isOnNetlify =
process.env.NETLIFY || process.env.URL?.endsWith('netlify.app') || Boolean(process.env.NETLIFY_FUNCTIONS_TOKEN);
getEnvVariable('NETLIFY') ||
(typeof getEnvVariable('URL') === 'string' && getEnvVariable('URL').endsWith('netlify.app')) ||
Boolean(getEnvVariable('NETLIFY_FUNCTIONS_TOKEN'));

const isDevelopmentInstance = isDevelopmentFromPublishableKey(publishableKey);
if (isOnNetlify && isDevelopmentInstance) {
const hasHandshakeQueryParam = locationHeader.includes('__clerk_handshake');
Expand Down
Loading