forked from github/plane
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
41 lines
943 B
TypeScript
41 lines
943 B
TypeScript
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// services
|
|
import userService from "services/user.service";
|
|
// ui
|
|
import { Spinner } from "components/ui";
|
|
// fetch-keys
|
|
import { CURRENT_USER } from "constants/fetch-keys";
|
|
|
|
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="h-screen grid place-items-center p-4">
|
|
<div className="flex flex-col items-center gap-3 text-center">
|
|
<h3 className="text-xl">Loading your profile...</h3>
|
|
<Spinner />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (error) {
|
|
const redirectTo = router.asPath;
|
|
|
|
router.push(`/?next=${redirectTo}`);
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|