Skip to content

Commit

Permalink
Log error when selected team member has no team
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Dec 27, 2024
1 parent ca8fa28 commit 8f710fb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/backend/src/app/api/v1/users/crud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { userIdOrMeSchema, yupBoolean, yupNumber, yupObject, yupString } from "@
import { validateBase64Image } from "@stackframe/stack-shared/dist/utils/base64";
import { decodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
import { getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { StackAssertionError, StatusError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { StackAssertionError, StatusError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { hashPassword, isPasswordHashValid } from "@stackframe/stack-shared/dist/utils/hashes";
import { deepPlainEquals } from "@stackframe/stack-shared/dist/utils/objects";
import { createLazyProxy } from "@stackframe/stack-shared/dist/utils/proxies";
Expand Down Expand Up @@ -316,8 +316,10 @@ export function getUserQuery(projectId: string, userId: string): RawQuery<UsersC
to_jsonb("TeamMember") ||
jsonb_build_object(
'Team', (
SELECT
to_jsonb("Team")
SELECT (
to_jsonb("Team") ||
jsonb_build_object()
)
FROM "Team"
WHERE "Team"."projectId" = "ProjectUser"."projectId" AND "Team"."teamId" = "TeamMember"."teamId"
)
Expand Down Expand Up @@ -350,6 +352,12 @@ export function getUserQuery(projectId: string, userId: string): RawQuery<UsersC
const otpAuth = row.AuthMethods.find((m: any) => m.OtpAuthMethod);
const passkeyAuth = row.AuthMethods.find((m: any) => m.PasskeyAuthMethod);

if (row.SelectedTeamMember && !row.SelectedTeamMember.team) {
// This seems to happen in production much more often than it should, so let's log some information for debugging
captureError("selected-team-member-and-team-consistency", new StackAssertionError("Selected team member has no team? Ignoring it", { row }));
row.SelectedTeamMember = null;
}

return {
id: row.projectUserId,
display_name: row.displayName,
Expand Down

0 comments on commit 8f710fb

Please sign in to comment.