Brijesh's Git Server — whodis @ master

built this as a refresher on handling webauthn

web/pages/protected.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
import React, { useContext } from "react";
import { AuthContext } from "../contexts/AuthContext";

const ProtectedPage: React.FC = () => {
  const { isAuthenticated, user, loading } = useContext(AuthContext);

  if (loading) {
    return <p>Loading...</p>;
  }

  if (!isAuthenticated || !user) {
    return (
      <div>
        <h1 className="text-2xl font-bold mb-4">Access Denied</h1>
        <p>You are not logged in.</p>
      </div>
    );
  }

  return (
    <div>
      <h1 className="text-2xl font-bold mb-4">Protected Page</h1>
      <p>Welcome, {user.displayName}!</p>
      <p>Your user ID is: {user.id}</p>
    </div>
  );
};

export default ProtectedPage;