summaryrefslogtreecommitdiff
path: root/front/src/routes/auth_successful.jsx
blob: 7c66587af573991250c4f00bd62328f953bab1d6 (plain)
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
41
42
43
44
45
46
47
import { useEffect } from "react";
import { Link } from "react-router-dom";

import { useAuthContext } from "../context/auth_context";

export const AuthSuccessful = () => {
  const { player, setPlayer, signedIn, setSignedIn, setSessionOver } =
    useAuthContext();

  useEffect(() => {
    fetch("/api/player/token/me", {
      credentials: "same-origin",
    })
      .then((r) => r.json())
      .then(({ player, expiration }) => {
        setSignedIn(!!player);
        setPlayer(player);
        setSessionOver(expiration);
      });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  if (signedIn) {
    return (
      <>
        <h3>Hello there, {player?.username || ""}! </h3>
        <div>
          <span> If you have not already done so: </span>
          <Link to="/keys" className="button">
            Add a Public Key
          </Link>
        </div>
        <br />
        <div>
          <Link to="/home" className="button">
            Go Home
          </Link>
        </div>
      </>
    );
  }
  return (
    <>
      <p>Loading...</p>
    </>
  );
};