diff options
Diffstat (limited to 'front/src/routes/auth_successful.jsx')
-rw-r--r-- | front/src/routes/auth_successful.jsx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/front/src/routes/auth_successful.jsx b/front/src/routes/auth_successful.jsx new file mode 100644 index 0000000..7c66587 --- /dev/null +++ b/front/src/routes/auth_successful.jsx @@ -0,0 +1,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> + </> + ); +}; |