-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): Crate with auth fixes (#6123)
Co-authored-by: Denis Kralj <[email protected]>
- Loading branch information
1 parent
b0d360e
commit 6d96ea5
Showing
46 changed files
with
475 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,60 @@ | ||
import { Navigate, useLocation } from 'react-router-dom'; | ||
import { type PropsWithChildren, useLayoutEffect } from 'react'; | ||
import { useAuth, useEnvironment } from './hooks'; | ||
import { isStudioRoute } from './studio/utils/routing'; | ||
import { useAuth, useEnvironment, useMonitoring, useRouteScopes } from './hooks'; | ||
import { ROUTES } from './constants/routes'; | ||
import { IS_EE_AUTH_ENABLED } from './config/index'; | ||
|
||
export function ApplicationReadyGuard({ children }: PropsWithChildren<{}>) { | ||
useMonitoring(); | ||
const location = useLocation(); | ||
const { isLoading: isLoadingAuth, inPublicRoute } = useAuth(); | ||
const { isLoading: isLoadingEnvironment } = useEnvironment(); | ||
const { inPublicRoute, inStudioRoute } = useRouteScopes(); | ||
const { isUserLoaded, isOrganizationLoaded, currentUser, currentOrganization } = useAuth(); | ||
const { isLoaded: isEnvironmentLoaded } = useEnvironment(); | ||
|
||
const isLoading = isStudioRoute(location.pathname) ? isLoadingAuth : isLoadingAuth && isLoadingEnvironment; | ||
const isLoaded = isUserLoaded && isOrganizationLoaded && isEnvironmentLoaded; | ||
|
||
// Clean up the skeleton loader when the app is ready | ||
useLayoutEffect(() => { | ||
if (inPublicRoute || !isLoading) { | ||
document.getElementById('loader')?.remove(); | ||
if (inPublicRoute || inStudioRoute || isLoaded) { | ||
const el = document.getElementById('loader'); | ||
|
||
if (!el) { | ||
return; | ||
} | ||
|
||
/* | ||
* Playwright doesn't always trigger transitionend, so we are using setTimeout | ||
* instead to remove the skeleton loader at the end of the animation. | ||
*/ | ||
setTimeout(() => el.remove(), 550); | ||
requestAnimationFrame(() => el.classList.add('fade-out')); | ||
} | ||
}, [inPublicRoute, inStudioRoute, isLoaded]); | ||
|
||
function isOnboardingComplete() { | ||
if (IS_EE_AUTH_ENABLED) { | ||
// TODO: replace with actual check property (e.g. isOnboardingCompleted) | ||
return currentOrganization?.productUseCases !== undefined; | ||
} | ||
}, [inPublicRoute, isLoading]); | ||
|
||
if (inPublicRoute || !isLoading) { | ||
return currentOrganization; | ||
} | ||
|
||
if (inPublicRoute || inStudioRoute) { | ||
return <>{children}</>; | ||
} | ||
|
||
return null; | ||
if (!isLoaded) { | ||
return null; | ||
} | ||
|
||
if (!currentUser && location.pathname !== ROUTES.AUTH_LOGIN) { | ||
return <Navigate to={ROUTES.AUTH_LOGIN} replace />; | ||
} | ||
|
||
if (!isOnboardingComplete() && location.pathname !== ROUTES.AUTH_APPLICATION) { | ||
return <Navigate to={ROUTES.AUTH_APPLICATION} replace />; | ||
} | ||
|
||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.