-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(nextjs): Decrease frequency of logs related to Keyless (#4953)
- Loading branch information
1 parent
3c0de05
commit 71e971a
Showing
6 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/nextjs': patch | ||
--- | ||
|
||
Decrease frequency of logs related to Keyless. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { AccountlessApplication } from '@clerk/backend'; | ||
import { isDevelopmentEnvironment } from '@clerk/shared/utils'; | ||
// 10 minutes in milliseconds | ||
const THROTTLE_DURATION_MS = 10 * 60 * 1000; | ||
|
||
function createClerkDevLogger() { | ||
if (!isDevelopmentEnvironment()) { | ||
return; | ||
} | ||
|
||
if (!global.__clerk_internal_keyless_logger) { | ||
global.__clerk_internal_keyless_logger = { | ||
__cache: new Map<string, { expiresAt: number }>(), | ||
|
||
log: function ({ cacheKey, msg }: { cacheKey: string; msg: string }) { | ||
if (this.__cache.has(cacheKey) && Date.now() < (this.__cache.get(cacheKey)?.expiresAt || 0)) { | ||
return; | ||
} | ||
|
||
console.log(msg); | ||
|
||
this.__cache.set(cacheKey, { | ||
expiresAt: Date.now() + THROTTLE_DURATION_MS, | ||
}); | ||
}, | ||
}; | ||
} | ||
|
||
return globalThis.__clerk_internal_keyless_logger; | ||
} | ||
|
||
export const createKeylessModeMessage = (keys: AccountlessApplication) => { | ||
return `\n\x1b[35m\n[Clerk]:\x1b[0m You are running in keyless mode.\nYou can \x1b[35mclaim your keys\x1b[0m by visiting ${keys.claimUrl}\n`; | ||
}; | ||
|
||
export const createConfirmationMessage = () => { | ||
return `\n\x1b[35m\n[Clerk]:\x1b[0m Your application is running with your claimed keys.\nYou can safely remove the \x1b[35m.clerk/\x1b[0m from your project.\n`; | ||
}; | ||
|
||
export const keylessLogger = createClerkDevLogger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters