File size: 977 Bytes
f8ca2a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
import { useState } from "react";
import "./PasswordPrompt.css";

export default function PasswordPrompt({ onAuthenticated }) {
  const [password, setPassword] = useState("");

  const handleSubmit = async (e) => {
    e.preventDefault();
    const res = await fetch("/api/post/authenticate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ password }),
    });
    const data = await res.json();
    if (res.ok) {
      onAuthenticated();
    } else {
      alert(data.message);
    }
  };

  return (
    <div className="password-prompt">
      <form onSubmit={handleSubmit}>
        <label>Access Code</label>
        <input
          type="password"
          value={password}
          onChange={(e) => setPassword(e.target.value)}
        />
        <button type="submit">
          <span className="material-symbols-outlined">login</span>Submit
        </button>
      </form>
    </div>
  );
}