chore: handled auth wrapper

This commit is contained in:
gurusainath 2024-05-01 19:12:17 +05:30
parent b87a43c8fe
commit 4054d52940

View File

@ -1,4 +1,5 @@
import { FC, ReactNode } from "react"; import { FC, ReactNode } from "react";
import { observer } from "mobx-react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import useSWR from "swr"; import useSWR from "swr";
import { Spinner } from "@plane/ui"; import { Spinner } from "@plane/ui";
@ -19,7 +20,7 @@ const isValidURL = (url: string): boolean => {
return !disallowedSchemes.test(url); return !disallowedSchemes.test(url);
}; };
export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => { export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props) => {
const router = useRouter(); const router = useRouter();
const { next_path } = router.query; const { next_path } = router.query;
// props // props
@ -34,7 +35,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
} = useUser(); } = useUser();
const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace(); const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace();
useSWR("USER_INFORMATION", () => fetchCurrentUser(), { useSWR("USER_INFORMATION", async () => fetchCurrentUser(), {
revalidateOnFocus: false, revalidateOnFocus: false,
shouldRetryOnError: false, shouldRetryOnError: false,
}); });
@ -42,7 +43,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
useSWR( useSWR(
currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null, currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null,
async () => { async () => {
if (currentUser) { if (currentUser && currentUser?.id) {
fetchCurrentUserSettings(); fetchCurrentUserSettings();
fetchUserProfile(); fetchUserProfile();
fetchWorkspaces(); fetchWorkspaces();
@ -126,4 +127,4 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = (props) => {
} }
return <>{children}</>; return <>{children}</>;
}; });