mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
1026ae3eb1
* chore: use estimate points hook created * chore: user auth layer * fix: build error
29 lines
705 B
TypeScript
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}</>;
|
|
};
|