plane/apps/app/layouts/auth-layout/user-authorization-wrapper.tsx
Aaryan Khandelwal 1026ae3eb1
chore: user auth layer (#749)
* chore: use estimate points hook created

* chore: user auth layer

* fix: build error
2023-04-08 18:05:54 +05:30

29 lines
705 B
TypeScript

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<Props> = ({ children }) => {
const router = useRouter();
const { data: currentUser, error } = useSWR(CURRENT_USER, () => userService.currentUser());
if (!currentUser && !error) {
return <div className="grid place-items-center h-screen">Loading...</div>;
}
if (error?.status === 401) {
const redirectTo = router.asPath;
router.push(`/signin?next=${redirectTo}`);
return null;
}
return <>{children}</>;
};