import { useState } from 'react'; import styles from './AdminGate.module.css'; const CORRECT_PIN = '2501'; export default function AdminGate({ children }) { const authed = sessionStorage.getItem('blog_admin_auth') === 'true'; const [pin, setPin] = useState(''); const [shake, setShake] = useState(false); const [passed, setPassed] = useState(authed); const handleDigit = (d) => { if (pin.length >= 4) return; const next = pin + d; setPin(next); if (next.length === 4) { if (next === CORRECT_PIN) { sessionStorage.setItem('blog_admin_auth', 'true'); setPassed(true); } else { setShake(true); setTimeout(() => { setPin(''); setShake(false); }, 600); } } }; const handleDelete = () => setPin(p => p.slice(0, -1)); if (passed) return children; return (
请输入 PIN 码