Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/app/api/reviews/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
.from("gigs")
.select("id, title, poster_id, status")
.eq("id", gig_id)
.single();
.maybeSingle();

if (!gig) {
return NextResponse.json({ error: "Gig not found" }, { status: 404 });
Expand All @@ -168,7 +168,7 @@
.eq("gig_id", gig_id)
.eq("applicant_id", user.id)
.eq("status", "accepted")
.single();
.maybeSingle();

const isAcceptedApplicant = !!application;

Expand All @@ -187,7 +187,7 @@
.eq("gig_id", gig_id)
.eq("applicant_id", reviewee_id)
.eq("status", "accepted")
.single();
.maybeSingle();

const revieweeIsAcceptedApplicant = !!revieweeApplication;

Expand All @@ -205,7 +205,7 @@
.eq("gig_id", gig_id)
.eq("reviewer_id", user.id)
.eq("reviewee_id", reviewee_id)
.single();
.maybeSingle();

if (existingReview) {
return NextResponse.json(
Expand Down Expand Up @@ -241,7 +241,7 @@
)
`
)
.single();
.maybeSingle();

if (createError) {
console.error("[POST /api/reviews] Supabase error:", createError);
Expand All @@ -254,18 +254,18 @@
.from("profiles")
.select("did")
.eq("id", reviewee_id)
.single();
.maybeSingle();
if (userDid) {
onReviewCreated(userDid, review.id, revieweeProfile?.did || undefined);

Check failure on line 259 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
Comment on lines 244 to 259

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Null review after insert causes crash

Switching the INSERT+SELECT from .single() to .maybeSingle() means both data and error can be null when Supabase allows the INSERT but the follow-up SELECT is blocked (e.g., a row-level-security policy that permits writes but not reads). The if (createError) guard on line 246 passes cleanly, and the code then crashes with TypeError: Cannot read properties of null (reading 'id') at every subsequent reference: review.id (lines 259, 265, 270, 275, 280, 284, 294, 297), review.reviewer, and review.reviewee. A missing-row null check needs to be added after the error guard, or .single() should be retained for this INSERT case since a successful insert always returns exactly one row.

}

// Log activity for reviewer
const reviewerProfile = Array.isArray(review.reviewer) ? review.reviewer[0] : review.reviewer;

Check failure on line 263 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.

Check failure on line 263 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.

Check failure on line 263 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
const revieweeProfileData = Array.isArray(review.reviewee) ? review.reviewee[0] : review.reviewee;

Check failure on line 264 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.

Check failure on line 264 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.

Check failure on line 264 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
void logActivity(supabase, {
userId: user.id,
activityType: "review_given",
referenceId: review.id,

Check failure on line 268 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
referenceType: "review",
metadata: { rating, gig_title: gig.title, reviewee_name: revieweeProfileData?.full_name || revieweeProfileData?.username },
});
Expand All @@ -275,7 +275,7 @@
void logActivity(serviceClient, {
userId: reviewee_id,
activityType: "review_received",
referenceId: review.id,

Check failure on line 278 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
referenceType: "review",
metadata: { rating, gig_title: gig.title, reviewer_name: reviewerProfile?.full_name || reviewerProfile?.username },
});
Expand All @@ -287,7 +287,7 @@
title: "New review received",
body: `You received a ${rating}-star review`,
data: {
review_id: review.id,

Check failure on line 290 in src/app/api/reviews/route.ts

View workflow job for this annotation

GitHub Actions / build

'review' is possibly 'null'.
gig_id,
rating,
},
Expand Down
Loading