All files / src/pages Callback.tsx

0% Statements 0/15
0% Branches 0/2
0% Functions 0/4
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                     
import React, { useEffect } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import { useAuth0 } from "@auth0/auth0-react";
 
interface CallbackResult {
  appState?: {
    returnTo?: string;
  };
}
 
const CallbackPage: React.FC = () => {
  const { handleRedirectCallback } = useAuth0();
  const navigate = useNavigate();
  const location = useLocation();
 
  useEffect(() => {
    const processAuth = async () => {
      try {
        // Parse appState from Auth0 callback
        const result: CallbackResult = await handleRedirectCallback();
        const returnTo =
          result.appState?.returnTo || import.meta.env.VITE_APP_LOGIN_URI;
 
        // Navigate to the page the user originally requested
        await navigate(returnTo, { replace: true });
      } catch (err) {
        console.error("Error handling Auth0 callback:", err);
        await navigate("/error", { replace: true });
      }
    };
 
    () => processAuth();
  }, [handleRedirectCallback, navigate, location]);
 
  return (
    <div>
      <h1>Logging in...</h1>
    </div>
  );
};
 
export default CallbackPage;