Skip to content

Commit

Permalink
fix: avoid infinite loop in usercontext
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-harris authored and skeptrunedev committed Aug 30, 2024
1 parent 34daf91 commit d86946c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions frontends/dashboard/src/components/CreateNewOrgModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
7 changes: 6 additions & 1 deletion frontends/dashboard/src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit d86946c

Please sign in to comment.