From 1c4a629bda8d1082489cb088799d63d87f895019 Mon Sep 17 00:00:00 2001 From: gurusainath Date: Thu, 2 May 2024 16:07:46 +0530 Subject: [PATCH] chore: updated authentication wrapper logic in web app --- web/lib/wrappers/authentication-wrapper.tsx | 22 ++++++--------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/web/lib/wrappers/authentication-wrapper.tsx b/web/lib/wrappers/authentication-wrapper.tsx index 64c0ba3b2..1e1cb74d0 100644 --- a/web/lib/wrappers/authentication-wrapper.tsx +++ b/web/lib/wrappers/authentication-wrapper.tsx @@ -27,12 +27,8 @@ export const AuthenticationWrapper: FC = observer((props const { children, pageType = EPageTypes.AUTHENTICATED } = props; // hooks const { isLoading: isUserLoading, data: currentUser, fetchCurrentUser } = useUser(); - const { isLoading: currentUserProfileLoader, data: currentUserProfile, fetchUserProfile } = useUserProfile(); - const { - isLoading: currentUserSettingsLoader, - data: currentUserSettings, - fetchCurrentUserSettings, - } = useUserSettings(); + const { isLoading: currentUserProfileLoader, data: currentUserProfile } = useUserProfile(); + const { isLoading: currentUserSettingsLoader, data: currentUserSettings } = useUserSettings(); const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace(); useSWR("USER_INFORMATION", async () => await fetchCurrentUser(), { @@ -42,13 +38,7 @@ export const AuthenticationWrapper: FC = observer((props useSWR( currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null, - async () => { - if (currentUser && currentUser?.id) { - await fetchCurrentUserSettings(); - await fetchUserProfile(); - await fetchWorkspaces(); - } - }, + async () => currentUser && currentUser?.id && (await fetchWorkspaces()), { revalidateOnFocus: false, shouldRetryOnError: false } ); @@ -87,7 +77,7 @@ export const AuthenticationWrapper: FC = observer((props if (pageType === EPageTypes.NON_AUTHENTICATED) { if (!currentUser?.id) return <>{children}; else { - if (currentUserProfile?.is_onboarded) { + if (currentUserProfile?.id && currentUserProfile?.is_onboarded) { const currentRedirectRoute = getWorkspaceRedirectionUrl(); router.push(currentRedirectRoute); return <>; @@ -103,7 +93,7 @@ export const AuthenticationWrapper: FC = observer((props router.push("/accounts/sign-in"); return <>; } else { - if (currentUser && currentUserProfile?.is_onboarded) { + if (currentUser && currentUserProfile?.id && currentUserProfile?.is_onboarded) { const currentRedirectRoute = getWorkspaceRedirectionUrl(); router.push(currentRedirectRoute); return <>; @@ -113,7 +103,7 @@ export const AuthenticationWrapper: FC = observer((props if (pageType === EPageTypes.AUTHENTICATED) { if (currentUser?.id) { - if (currentUserProfile?.is_onboarded) return <>{children}; + if (currentUserProfile?.id && currentUserProfile?.is_onboarded) return <>{children}; else { router.push(`/onboarding`); return <>;