Skip to content

Commit

Permalink
Prevent "Attempt to read customer_id on null" (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Jan 19, 2023
1 parent a571c81 commit 5244f59
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Controllers/AlertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __invoke(Request $request)
{
abort_if(!$request->header('authorization'), 401);
$customer = DB::table('oauth_token')->select('customer_id')->where('token', str_replace('Bearer ', '', $request->header('authorization')))->first();
abort_if(!$customer->customer_id, 401);
abort_if(!$customer?->customer_id, 401);
$alerts = DB::table('product_alert_stock')->select('product_id')->where('customer_id', $customer->customer_id)->get();

return $alerts->pluck('product_id')->toJson() ?? [];
Expand Down

0 comments on commit 5244f59

Please sign in to comment.