-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Log usage of
protect()
in pages,routes or actions
- Loading branch information
1 parent
0ee4640
commit e8aff3f
Showing
5 changed files
with
63 additions
and
8 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,8 @@ | ||
--- | ||
"@clerk/nextjs": minor | ||
"@clerk/shared": minor | ||
"@clerk/types": minor | ||
--- | ||
|
||
Telemetry: Log usage of `auth.protect()` inside pages, routes, or actions. | ||
- Only applications with `experimental.after` turned on, otherwise it will be a noop. |
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,28 @@ | ||
import { isNextFetcher } from './nextFetcher'; | ||
|
||
export type AfterTask<T = unknown> = Promise<T> | AfterCallback<T>; | ||
export type AfterCallback<T = unknown> = () => T | Promise<T>; | ||
|
||
export async function safe_after<T>(task: AfterTask<T>): Promise<void> { | ||
const __fetch = globalThis.fetch; | ||
|
||
if (!isNextFetcher(__fetch)) { | ||
return; | ||
} | ||
|
||
const { afterContext } = __fetch.__nextGetStaticStore().getStore() || {}; | ||
|
||
if (!afterContext) { | ||
// If the application does not have the experimental flag turned on it needs to be a noop, otherwise Next.js will throw | ||
return; | ||
} | ||
|
||
// @ts-ignore | ||
const { unstable_after } = (await import('next/server.js')) || {}; | ||
if (!unstable_after) { | ||
// Application uses a nextjs version that does not export the utility | ||
return; | ||
} | ||
|
||
unstable_after(task); | ||
} |
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