NewWacht Bench is live — AI-assisted development for Wacht

useActiveWorkspace() hook

useActiveWorkspace() is the active-scope wrapper over useWorkspaceList(). It resolves the current active workspace and active workspace membership from the session, then rebinds the workspace-level management methods so they operate on that active workspace automatically.

Usage

The following example shows a basic usage of useActiveWorkspace().

export default function ActiveWorkspaceHeader() {  const { activeWorkspace, loading } = useActiveWorkspace();  if (loading) {    return <p>Loading workspace…</p>;  }  return <p>{activeWorkspace?.name ?? 'No active workspace'}</p>;}

Return value

The hook returns the following fields and methods.

activeWorkspace: Workspace | null;
Workspace whose membership identifier matches the active sign-in in the session.
id?: string | undefined;
Workspace identifier.
name?: string | undefined;
Workspace name.
image_url?: string | undefined;
Workspace image URL.
description?: string | undefined;
Workspace description.
member_count?: number | undefined;
Workspace member count.
enforce_2fa?: boolean | undefined;
Whether the workspace enforces 2FA.
enable_ip_restriction?: boolean | undefined;
Whether the workspace uses IP restrictions.
activeMembership: WorkspaceMembership | null;
Current active workspace membership resolved from the session.
id?: string | undefined;
Workspace-membership identifier.
workspace?: Workspace | undefined;
Workspace attached to the active membership.
organization?: Organization | undefined;
Parent organization attached to the active workspace membership.
roles?: WorkspaceRole[] | undefined;
Roles attached to the active workspace membership.
[].id?: string | undefined;
Role identifier.
[].name?: string | undefined;
Role name.
[].permissions?: string[] | undefined;
Permissions granted by the role.
eligibility_restriction?: { type: "none" | "ip_not_allowed" | "mfa_required" | "ip_and_mfa_required"; message: string } | undefined | undefined;
Eligibility restriction attached to the membership when one exists.
loading: boolean;
Whether the session or the underlying workspace list is still loading.
error: Error | null;
Combined loading error from the session branch or the workspace-list branch.
refetch: () => Promise<void>;
Revalidates the underlying workspace memberships query.
leave?: () => Promise<void | undefined> | undefined;
Leaves the active workspace using the current sign-in user ID.
updateWorkspace?: (data: { name?: string; description?: string; image?: File; enforce_2fa?: boolean; enable_ip_restriction?: boolean; whitelisted_ips?: string[] }) => Promise<unknown> | undefined;
Updates the active workspace.
deleteWorkspace?: () => Promise<unknown> | undefined;
Deletes the active workspace.
getMembers?: (params?: { page: number; limit: number; search?: string }) => Promise<PaginatedResponse<WorkspaceMembership[]> | { data: []; meta: { total: number; page: number; limit: number } }> | undefined;
Loads members for the active workspace.
getRoles?: () => Promise<WorkspaceRole[]> | undefined;
Loads roles for the active workspace.
createRole?: (name: string, permissions: string[]) => Promise<WorkspaceRole | undefined> | undefined;
Creates a role on the active workspace.
deleteRole?: (role: WorkspaceRole) => Promise<unknown> | undefined;
Deletes a role from the active workspace.
removeMember?: (memberId: string) => Promise<unknown> | undefined;
Removes a member from the active workspace.
addMemberRole?: (membershipId: string, roleId: string) => Promise<unknown> | undefined;
Adds a role to a member in the active workspace.
removeMemberRole?: (membershipId: string, roleId: string) => Promise<unknown> | undefined;
Removes a role from a member in the active workspace.
getInvitations?: () => Promise<any[]> | undefined;
Loads invitations for the active workspace.
inviteMember?: (params: { email: string; workspaceRoleId?: string }) => Promise<unknown> | undefined;
Invites a member into the active workspace.
discardInvitation?: (invitationId: string) => Promise<unknown> | undefined;
Discards an invitation from the active workspace.
resendInvitation?: (invitationId: string) => Promise<unknown> | undefined;
Resends an invitation from the active workspace.

How it works

This hook is not a separate data source. It wraps useWorkspaceList() and useSession(), then resolves one active workspace and one active membership from the current session.
All of the management methods are rebound to the current active workspace, so callers no longer pass a workspace argument each time.
Invitation helpers need the active workspace together with its parent organization. The hook resolves that by matching the active workspace back into the broader workspaces list from useWorkspaceList().
When there is no active workspace, many methods return empty values or undefined instead of throwing. The docs reflect that behavior because it is part of the current implementation contract.
This is the right hook for workspace-aware pages such as workspace settings, members, roles, and invitations that should always operate on the active workspace only.

When to use it

    Examples

    Render the active workspace name

    export default function ActiveWorkspaceTitle() {  const { activeWorkspace, loading } = useActiveWorkspace();  if (loading) {    return <p>Loading workspace…</p>;  }  return <p>{activeWorkspace?.name ?? 'No active workspace'}</p>;}

    Load members for the active workspace

    export default function ActiveWorkspaceMembers() {  const { loading, getMembers } = useActiveWorkspace();  async function loadMembers() {    if (loading) {      return;    }    const result = await getMembers({      page: 1,      limit: 20,    });    console.log(result);  }  return <button onClick={loadMembers}>Load members</button>;}

    Invite a member into the active workspace

    export default function InviteWorkspaceMember() {  const { loading, inviteMember } = useActiveWorkspace();  async function invite() {    if (loading) {      return;    }    await inviteMember({      email: 'jane@example.com',    });  }  return <button onClick={invite}>Invite member</button>;}

    On this page