Commit 9388110e authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

RequireAuth 컴포넌트 추가

parent 4ff854ff
import React, { FC } from "react";
import { Navigate, useLocation } from "react-router-dom";
import { useAuth } from "./auth.context";
export const RequireAuth: FC<{ children: JSX.Element }> = ({ children }) => {
const { user } = useAuth();
const location = useLocation();
if (!user.isLoggedIn) {
return (
<Navigate to={"/login"} state={{ from: location.pathname }} replace />
);
}
return children;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment