import useSWR from "swr"; import { CURRENT_USER } from "constants/fetch-keys"; import userService from "services/user.service"; import { useRouter } from "next/router"; type Props = { children: React.ReactNode; }; export const UserAuthorizationLayout: React.FC = ({ children }) => { const router = useRouter(); const { data: currentUser, error } = useSWR(CURRENT_USER, () => userService.currentUser()); if (!currentUser && !error) { return
Loading...
; } if (error?.status === 401) { const redirectTo = router.asPath; router.push(`/signin?next=${redirectTo}`); return null; } return <>{children}; };