Brijesh's Git Server — k3yst0n3 @ 47493b53290ea602660736c157d63e1fa708e704

client/pages/index.tsx (view raw)

 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
import { GetCookie, SetCookie } from "@/helpers/cookie";
import ParseJWT from "@/helpers/jwt";
import Link from "next/link";
import React from "react";

function IndexPage() {
  const [tokenData, setTokenData] = React.useState<any>()

  React.useEffect(() => {
    setTokenData(ParseJWT(GetCookie("token") || "{}"))
  }, []);

  return (
    <div className="flex flex-col gap-1 m-4">
      <h1>K3YST0N3</h1>
      {tokenData
        ? <div>
          <pre>{JSON.stringify(tokenData, null, 2)}</pre>
          <button className="border border-gray-400 rounded px-2 py-1" onClick={() => {
            SetCookie("token", "", -1)
            setTokenData(undefined)
          }}>Logout</button>
        </div>
        : <>
          <Link
            href="/login"
            className="text-blue-600 underline"
          >Login</Link>
          <Link
            href="/register"
            className="text-blue-600 underline"
          >Register</Link>
        </>
      }
    </div>
  );
}

export default IndexPage;