Skip to content

Commit

Permalink
fix: fix race condition for global project redirect
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
MasWho committed Feb 13, 2025
1 parent 86b6411 commit e253487
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/context/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createContext, FC, ReactNode, useContext } from "react";
import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "util/queryKeys";
import { fetchCertificates } from "api/certificates";
import { useSettings } from "context/useSettings";
import { fetchProjects } from "api/projects";
import { fetchCurrentIdentity } from "api/auth-identities";
import { useSupportedFeatures } from "./useSupportedFeatures";
Expand Down Expand Up @@ -36,12 +35,10 @@ interface ProviderProps {
}

export const AuthProvider: FC<ProviderProps> = ({ children }) => {
const { data: settings, isLoading } = useSettings();

const { hasEntitiesWithEntitlements, isSettingsLoading } =
const { hasEntitiesWithEntitlements, isSettingsLoading, settings } =
useSupportedFeatures();

const { data: currentIdentity } = useQuery({
const { data: currentIdentity, isLoading: isIdentityLoading } = useQuery({
queryKey: [queryKeys.currentIdentity],
queryFn: fetchCurrentIdentity,
retry: false, // avoid retry for older versions of lxd less than 5.21 due to missing endpoint
Expand All @@ -60,7 +57,7 @@ export const AuthProvider: FC<ProviderProps> = ({ children }) => {
const { data: projects = [], isLoading: isProjectsLoading } = useQuery({
queryKey: [queryKeys.projects],
queryFn: () => fetchProjects(isFineGrained()),
enabled: settings?.auth === "trusted" && isFineGrained() !== null,
enabled: settings?.auth !== "trusted" && isFineGrained() !== null,
});

const defaultProject =
Expand Down Expand Up @@ -91,7 +88,8 @@ export const AuthProvider: FC<ProviderProps> = ({ children }) => {
value={{
isAuthenticated: (settings && settings.auth !== "untrusted") ?? false,
isOidc: settings?.auth_user_method === "oidc",
isAuthLoading: isLoading,
isAuthLoading:
isSettingsLoading || isIdentityLoading || isProjectsLoading,
isRestricted,
defaultProject,
hasNoProjects: projects.length === 0 && !isProjectsLoading,
Expand Down

0 comments on commit e253487

Please sign in to comment.