Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/app/api/api-keys/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export async function POST(request: NextRequest) {
scope,
})
.select("id, name, key_prefix, created_at, expires_at, scope")
.single();
.maybeSingle();

if (error || !apiKey) {
console.error("API key creation error:", error);
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/profile/wallet-addresses/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function GET(request: NextRequest) {
.from("profiles")
.select("wallet_addresses")
.eq("id", user.id)
.single();
.maybeSingle();

const posterAddresses = Array.isArray(posterProfile?.wallet_addresses)
? posterProfile.wallet_addresses
Expand All @@ -51,7 +51,7 @@ export async function GET(request: NextRequest) {
.from("gigs")
.select("id, poster_id")
.eq("id", gigId)
.single();
.maybeSingle();

if (!gig || gig.poster_id !== user.id) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
Expand All @@ -76,7 +76,7 @@ export async function GET(request: NextRequest) {
.from("profiles")
.select("wallet_addresses")
.eq("id", workerId)
.single();
.maybeSingle();

workerAddresses = Array.isArray(workerProfile?.wallet_addresses)
? workerProfile.wallet_addresses
Expand Down
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 246 to 260

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 Missing null check after .maybeSingle() on INSERT

The code only checks createError but not !review after the insert. With .maybeSingle(), a successful insert where RLS prevents the SELECT from returning the row yields { data: null, error: null }. With .single() that scenario produced a PGRST116 error caught in createError. Now review is silently null, and the first access at review.id on line 259 (and review.reviewer/review.reviewee on lines 263–264) throws a TypeError, collapsing the entire handler into the generic 500 catch block instead of returning a meaningful response.


// 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
2 changes: 1 addition & 1 deletion src/app/api/saved-gigs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function POST(request: NextRequest) {
gig_id,
})
.select()
.single();
.maybeSingle();

if (error) {
return NextResponse.json({ error: error.message }, { status: 400 });
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/work-history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function POST(request: NextRequest) {
...validationResult.data,
})
.select()
.single();
.maybeSingle();

if (error) {
return NextResponse.json({ error: error.message }, { status: 400 });
Expand Down
Loading