Skip to content

Commit 65bdaa9

Browse files
josephfuscoCopilot
andauthored
Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8fedd1a commit 65bdaa9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

examples/next/toolbar-demo/example-app/lib/wordpress.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@ export async function fetchFromWordPress(endpoint: string, options?: RequestInit
2525
}
2626

2727
export async function getCurrentUser() {
28-
// Demo: Using user ID 1 (wp-env default admin) for simplicity
29-
// Production: Use /wp/v2/users/me with Application Passwords or OAuth
30-
// Note: This is acceptable in demos where auth setup would add unnecessary complexity
28+
// 🚨 WARNING: Demo-only code! 🚨
29+
// This function uses a hardcoded user ID (1), which is the default admin in wp-env.
30+
// DO NOT USE THIS PATTERN IN PRODUCTION. In production, use /wp/v2/users/me with proper authentication.
31+
if (process.env.NODE_ENV === 'production') {
32+
throw new Error(
33+
'getCurrentUser() uses a hardcoded user ID and MUST NOT be used in production. ' +
34+
'Use /wp/v2/users/me with Application Passwords or OAuth instead.'
35+
);
36+
}
37+
if (typeof window !== 'undefined' && window.console && window.console.warn) {
38+
window.console.warn(
39+
'WARNING: getCurrentUser() is using a hardcoded user ID (1). ' +
40+
'This is for demo purposes only and MUST NOT be used in production.'
41+
);
42+
}
3143
return fetchFromWordPress('/wp/v2/users/1');
3244
}
3345

0 commit comments

Comments
 (0)