Spaces:
Running
Running
Create contexts/SecurityContext.tsx
Browse files- contexts/SecurityContext.tsx +27 -0
contexts/SecurityContext.tsx
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { createContext, useContext, useState } from 'react';
|
| 2 |
+
|
| 3 |
+
interface SecurityContextType {
|
| 4 |
+
isSensitiveUnlocked: boolean;
|
| 5 |
+
unlockSensitiveContent: () => void;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
const SecurityContext = createContext<SecurityContextType>({
|
| 9 |
+
isSensitiveUnlocked: false,
|
| 10 |
+
unlockSensitiveContent: () => {},
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
export const SecurityProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
| 14 |
+
const [isSensitiveUnlocked, setIsSensitiveUnlocked] = useState(false);
|
| 15 |
+
|
| 16 |
+
const unlockSensitiveContent = () => {
|
| 17 |
+
setIsSensitiveUnlocked(true);
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
return (
|
| 21 |
+
<SecurityContext.Provider value={{ isSensitiveUnlocked, unlockSensitiveContent }}>
|
| 22 |
+
{children}
|
| 23 |
+
</SecurityContext.Provider>
|
| 24 |
+
);
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
export const useSecurity = () => useContext(SecurityContext);
|