Skip to content

Commit 99e33e5

Browse files
committed
chore: remove organizationIds from AuthProvider
1 parent f21f2dc commit 99e33e5

File tree

6 files changed

+9
-33
lines changed

6 files changed

+9
-33
lines changed

site/src/contexts/auth/AuthProvider.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export type AuthContextValue = {
3030
isUpdatingProfile: boolean;
3131
user: User | undefined;
3232
permissions: Permissions | undefined;
33-
organizationIds: readonly string[] | undefined;
3433
signInError: unknown;
3534
updateProfileError: unknown;
3635
signOut: () => void;
@@ -119,7 +118,6 @@ export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
119118
permissions: permissionsQuery.data as Permissions | undefined,
120119
signInError: loginMutation.error,
121120
updateProfileError: updateProfileMutation.error,
122-
organizationIds: userQuery.data?.organization_ids,
123121
}}
124122
>
125123
{children}

site/src/contexts/auth/RequireAuth.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe("useAuthenticated", () => {
9595
wrapper: createAuthWrapper({
9696
user: MockUser,
9797
permissions: MockPermissions,
98-
organizationIds: [],
9998
}),
10099
});
101100
}).not.toThrow();

site/src/contexts/auth/RequireAuth.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type RequireKeys<T, R extends keyof T> = Omit<T, R> & {
7474
// values are not undefined when authenticated
7575
type AuthenticatedAuthContextValue = RequireKeys<
7676
AuthContextValue,
77-
"user" | "permissions" | "organizationIds"
77+
"user" | "permissions"
7878
>;
7979

8080
export const useAuthenticated = (): AuthenticatedAuthContextValue => {
@@ -88,9 +88,5 @@ export const useAuthenticated = (): AuthenticatedAuthContextValue => {
8888
throw new Error("Permissions are not available.");
8989
}
9090

91-
if (!auth.organizationIds) {
92-
throw new Error("Organization ID is not available.");
93-
}
94-
9591
return auth as AuthenticatedAuthContextValue;
9692
};

site/src/modules/dashboard/DashboardProvider.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import type {
1515
} from "api/typesGenerated";
1616
import { Loader } from "components/Loader/Loader";
1717
import { useAuthenticated } from "contexts/auth/RequireAuth";
18-
import { useEffectEvent } from "hooks/hookPolyfills";
1918
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
2019

2120
export interface DashboardValue {
21+
/**
22+
* @deprecated Do not add new usage of this value. It is being removed as part
23+
* of the multi-org work.
24+
*/
2225
organizationId: string;
23-
setOrganizationId: (id: string) => void;
2426
entitlements: Entitlements;
2527
experiments: Experiments;
2628
appearance: AppearanceConfig;
@@ -32,40 +34,22 @@ export const DashboardContext = createContext<DashboardValue | undefined>(
3234

3335
export const DashboardProvider: FC<PropsWithChildren> = ({ children }) => {
3436
const { metadata } = useEmbeddedMetadata();
35-
const { user, organizationIds } = useAuthenticated();
37+
const { user } = useAuthenticated();
3638
const entitlementsQuery = useQuery(entitlements(metadata.entitlements));
3739
const experimentsQuery = useQuery(experiments(metadata.experiments));
3840
const appearanceQuery = useQuery(appearance(metadata.appearance));
3941

4042
const isLoading =
4143
!entitlementsQuery.data || !appearanceQuery.data || !experimentsQuery.data;
4244

43-
const lastUsedOrganizationId = localStorage.getItem(
44-
`user:${user.id}.lastUsedOrganizationId`,
45-
);
46-
const [activeOrganizationId, setActiveOrganizationId] = useState(() =>
47-
lastUsedOrganizationId && organizationIds.includes(lastUsedOrganizationId)
48-
? lastUsedOrganizationId
49-
: organizationIds[0],
50-
);
51-
52-
const setOrganizationId = useEffectEvent((id: string) => {
53-
if (!organizationIds.includes(id)) {
54-
throw new ReferenceError("Invalid organization ID");
55-
}
56-
localStorage.setItem(`user:${user.id}.lastUsedOrganizationId`, id);
57-
setActiveOrganizationId(id);
58-
});
59-
6045
if (isLoading) {
6146
return <Loader fullscreen />;
6247
}
6348

6449
return (
6550
<DashboardContext.Provider
6651
value={{
67-
organizationId: activeOrganizationId,
68-
setOrganizationId: setOrganizationId,
52+
organizationId: user.organization_ids[0] ?? "default",
6953
entitlements: entitlementsQuery.data,
7054
experiments: experimentsQuery.data,
7155
appearance: appearanceQuery.data,

site/src/pages/ManagementSettingsPage/ManagementSettingsLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const useOrganizationSettings = (): OrganizationSettingsContextValue => {
3535

3636
export const ManagementSettingsLayout: FC = () => {
3737
const location = useLocation();
38-
const { permissions, organizationIds } = useAuthenticated();
38+
const { permissions } = useAuthenticated();
3939
const { experiments } = useDashboard();
4040
const { organization } = useParams() as { organization: string };
4141
const deploymentConfigQuery = useQuery(deploymentConfig());
@@ -61,7 +61,7 @@ export const ManagementSettingsLayout: FC = () => {
6161
currentOrganizationId: !inOrganizationSettings
6262
? undefined
6363
: !organization
64-
? organizationIds[0]
64+
? organizationsQuery.data[0]?.id
6565
: organizationsQuery.data.find(
6666
(org) => org.name === organization,
6767
)?.id,

site/src/testHelpers/storybook.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const withDashboardProvider = (
2727
<DashboardContext.Provider
2828
value={{
2929
organizationId: "",
30-
setOrganizationId: () => {},
3130
entitlements,
3231
experiments,
3332
appearance: MockAppearanceConfig,

0 commit comments

Comments
 (0)