mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: updated authentication wrapper logic in web app
This commit is contained in:
parent
9ea5caed1b
commit
1c4a629bda
@ -27,12 +27,8 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
|
|||||||
const { children, pageType = EPageTypes.AUTHENTICATED } = props;
|
const { children, pageType = EPageTypes.AUTHENTICATED } = props;
|
||||||
// hooks
|
// hooks
|
||||||
const { isLoading: isUserLoading, data: currentUser, fetchCurrentUser } = useUser();
|
const { isLoading: isUserLoading, data: currentUser, fetchCurrentUser } = useUser();
|
||||||
const { isLoading: currentUserProfileLoader, data: currentUserProfile, fetchUserProfile } = useUserProfile();
|
const { isLoading: currentUserProfileLoader, data: currentUserProfile } = useUserProfile();
|
||||||
const {
|
const { isLoading: currentUserSettingsLoader, data: currentUserSettings } = useUserSettings();
|
||||||
isLoading: currentUserSettingsLoader,
|
|
||||||
data: currentUserSettings,
|
|
||||||
fetchCurrentUserSettings,
|
|
||||||
} = useUserSettings();
|
|
||||||
const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace();
|
const { loader: workspaceLoader, workspaces, fetchWorkspaces } = useWorkspace();
|
||||||
|
|
||||||
useSWR("USER_INFORMATION", async () => await fetchCurrentUser(), {
|
useSWR("USER_INFORMATION", async () => await fetchCurrentUser(), {
|
||||||
@ -42,13 +38,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
|
|||||||
|
|
||||||
useSWR(
|
useSWR(
|
||||||
currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null,
|
currentUser && currentUser?.id ? "USER_PROFILE_SETTINGS_INFORMATION" : null,
|
||||||
async () => {
|
async () => currentUser && currentUser?.id && (await fetchWorkspaces()),
|
||||||
if (currentUser && currentUser?.id) {
|
|
||||||
await fetchCurrentUserSettings();
|
|
||||||
await fetchUserProfile();
|
|
||||||
await fetchWorkspaces();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -87,7 +77,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
|
|||||||
if (pageType === EPageTypes.NON_AUTHENTICATED) {
|
if (pageType === EPageTypes.NON_AUTHENTICATED) {
|
||||||
if (!currentUser?.id) return <>{children}</>;
|
if (!currentUser?.id) return <>{children}</>;
|
||||||
else {
|
else {
|
||||||
if (currentUserProfile?.is_onboarded) {
|
if (currentUserProfile?.id && currentUserProfile?.is_onboarded) {
|
||||||
const currentRedirectRoute = getWorkspaceRedirectionUrl();
|
const currentRedirectRoute = getWorkspaceRedirectionUrl();
|
||||||
router.push(currentRedirectRoute);
|
router.push(currentRedirectRoute);
|
||||||
return <></>;
|
return <></>;
|
||||||
@ -103,7 +93,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
|
|||||||
router.push("/accounts/sign-in");
|
router.push("/accounts/sign-in");
|
||||||
return <></>;
|
return <></>;
|
||||||
} else {
|
} else {
|
||||||
if (currentUser && currentUserProfile?.is_onboarded) {
|
if (currentUser && currentUserProfile?.id && currentUserProfile?.is_onboarded) {
|
||||||
const currentRedirectRoute = getWorkspaceRedirectionUrl();
|
const currentRedirectRoute = getWorkspaceRedirectionUrl();
|
||||||
router.push(currentRedirectRoute);
|
router.push(currentRedirectRoute);
|
||||||
return <></>;
|
return <></>;
|
||||||
@ -113,7 +103,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
|
|||||||
|
|
||||||
if (pageType === EPageTypes.AUTHENTICATED) {
|
if (pageType === EPageTypes.AUTHENTICATED) {
|
||||||
if (currentUser?.id) {
|
if (currentUser?.id) {
|
||||||
if (currentUserProfile?.is_onboarded) return <>{children}</>;
|
if (currentUserProfile?.id && currentUserProfile?.is_onboarded) return <>{children}</>;
|
||||||
else {
|
else {
|
||||||
router.push(`/onboarding`);
|
router.push(`/onboarding`);
|
||||||
return <></>;
|
return <></>;
|
||||||
|
Loading…
Reference in New Issue
Block a user