-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseSecurity.js
More file actions
32 lines (27 loc) 路 1.01 KB
/
Copy pathuseSecurity.js
File metadata and controls
32 lines (27 loc) 路 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useEffect } from 'react';
export const useSecurity = () => {
useEffect(() => {
// 1. Disable Right Click (Context Menu)
const handleContextMenu = (e) => e.preventDefault();
// 2. Disable Keyboard Shortcuts (F12, Ctrl+Shift+I, Ctrl+U, etc.)
const handleKeyDown = (e) => {
if (
e.key === 'F12' ||
(e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'J' || e.key === 'C')) ||
(e.ctrlKey && e.key === 'U') ||
(e.ctrlKey && e.key === 'S') // Prevent saving the page
) {
e.preventDefault();
return false;
}
};
// The debuggerTrap interval has been removed to stop the site
// from automatically pausing when DevTools are detected.
document.addEventListener('contextmenu', handleContextMenu);
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('contextmenu', handleContextMenu);
document.removeEventListener('keydown', handleKeyDown);
};
}, []);
};