* Initialize a new NX project - QR campaign * Develop QR code generator app for campaign * Add deployment script Add Dockerfile, docker compose, and update Nix config for deployment * Revert package.json to fix ci * Revert package-lock.json to ensure ci (Nix build & cache) successful
22 lines
751 B
TypeScript
22 lines
751 B
TypeScript
import React from 'react';
|
|
import { Navigate, useLocation } from 'react-router-dom';
|
|
import { useAuthStore } from '../../../features/auth/store/auth.store';
|
|
|
|
interface RequireAuthProps {
|
|
children: JSX.Element;
|
|
}
|
|
|
|
export const RequireAuth = ({ children }: RequireAuthProps) => {
|
|
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
|
const location = useLocation();
|
|
|
|
if (!isAuthenticated) {
|
|
// Redirect them to the /login page, but save the current location they were
|
|
// trying to go to when they were redirected. This allows us to send them
|
|
// along to that page after they login, which is a nicer user experience.
|
|
return <Navigate to="/login" state={{ from: location }} replace />;
|
|
}
|
|
|
|
return children;
|
|
};
|