Restore membership scoping for user-scoped getTeam/useTeam

Co-Authored-By: aman <aman@stack-auth.com>
This commit is contained in:
Devin AI 2026-07-14 02:08:41 +00:00
parent b83db37dda
commit 4e2e8cf5e1
2 changed files with 10 additions and 8 deletions

View File

@ -723,16 +723,20 @@ export class _HexclaveServerAppImplIncomplete<HasTokenStore extends boolean, Pro
},
// END_PLATFORM
selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
// Unlike the app-level getTeam/useTeam (which fetch any team by id),
// the user-scoped variants search the user's own team list on purpose:
// they must return null for teams the user is not a member of, and some
// callers rely on that as a membership check.
async getTeam(teamId: string) {
const team = Result.orThrow(await app._serverTeamCache.getOrWait([teamId], "write-only"));
return team == null ? null : app._serverTeamFromCrud(team);
const teams = await this.listTeams();
return teams.find((t) => t.id === teamId) ?? null;
},
// IF_PLATFORM react-like
useTeam(teamId: string) {
const team = useAsyncCache(app._serverTeamCache, [teamId], "user.useTeam()");
const teams = this.useTeams();
return useMemo(() => {
return team == null ? null : app._serverTeamFromCrud(team);
}, [team]);
return teams.find((t) => t.id === teamId) ?? null;
}, [teams, teamId]);
},
// END_PLATFORM
async listTeams(options?: ServerListTeamsOptions): Promise<ServerTeam[] & { nextCursor: string | null }> {

View File

@ -113,9 +113,7 @@ teamId: string
Returns: ServerTeam | null
GET /api/v1/teams/{teamId} [server-only]
Returns the team with the requested ID, or null if it does not exist.
Find in listTeams() by id. This is deliberately scoped to the user's own team memberships (unlike the app-level getTeam), so it returns null for teams the user is not a member of.
Does not error.