Skip to content

Commit

Permalink
fix: make UI consistent as user waits for backend creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Sep 16, 2023
1 parent e5c5ff8 commit e7e2f8d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/Authentication/Clerk/ClerkAuthContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default function ClerkAuthContextProvider({
// when organization is switched, we need to re-fetch the user and the UI
const { organization } = useOrganization();

const backendURL = organization?.publicMetadata.backend_url;

const {
data: payload,
isLoading,
Expand All @@ -25,17 +27,21 @@ export default function ClerkAuthContextProvider({
["user", "whoami", organization],
() => whoami(),
{
enabled: !!backendURL,
refetchOnWindowFocus: false,
refetchInterval: 0,
refetchOnReconnect: false
}
);

if (isLoading && !payload) {
return <FullPageSkeletonLoader />;
// if the organization backend is not yet created, we need to wait for it to
// be created before showing the UI
if (!backendURL) {
return <InstanceCreationInProgress />;
}

// if the organization backend is not yet created, we need to wait for it to
// if the organization backend returns a 404 or a 5xx error, we need to wait
// for it to be created before showing the UI
if (
error &&
(error.response?.status?.toString().startsWith("5") ||
Expand All @@ -44,6 +50,10 @@ export default function ClerkAuthContextProvider({
return <InstanceCreationInProgress />;
}

if (isLoading && !payload) {
return <FullPageSkeletonLoader />;
}

if (error && !payload) {
return <ErrorPage error={error} />;
}
Expand Down

0 comments on commit e7e2f8d

Please sign in to comment.