diff --git a/frontends/dashboard/src/components/CreateNewOrgModal.tsx b/frontends/dashboard/src/components/CreateNewOrgModal.tsx index 361f077a70..8896a928e3 100644 --- a/frontends/dashboard/src/components/CreateNewOrgModal.tsx +++ b/frontends/dashboard/src/components/CreateNewOrgModal.tsx @@ -48,6 +48,8 @@ export const NewOrgModal = (props: NewOrgModalProps) => { void res.json().then((data) => { userContext.setSelectedOrganizationId((data as Organization).id); + // Refresh the user context with the new organization + userContext.login(); navigate(`/dashboard/${(data as Organization).id}/overview`); diff --git a/frontends/dashboard/src/contexts/UserContext.tsx b/frontends/dashboard/src/contexts/UserContext.tsx index d4d0d5a8c1..79848724de 100644 --- a/frontends/dashboard/src/contexts/UserContext.tsx +++ b/frontends/dashboard/src/contexts/UserContext.tsx @@ -103,7 +103,12 @@ export const UserContextWrapper = (props: UserStoreContextProps) => { const userOrgIds = user()?.user_orgs.map((org) => org.organization_id); - if (!userOrgIds?.includes(organizationId ?? "")) { + // If the selected organization isn't in the users list, + // restart login procedure + if ( + !userOrgIds?.includes(organizationId ?? "") && + userOrgIds?.length !== 0 + ) { login(); }