fix/headerauth-crash-missing-header #19
@ -15,7 +15,7 @@ class HeaderAuth
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next): Response
|
public function handle(Request $request, Closure $next): Response
|
||||||
{
|
{
|
||||||
if (is_null($request->header('X-BOTAUTH'))) {
|
if (empty($request->header('X-BOTAUTH'))) {
|
||||||
|
|
|||||||
return response()
|
return response()
|
||||||
->json(["status" => false, "message" => "Unauthorized."], 401);
|
->json(["status" => false, "message" => "Unauthorized."], 401);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user
If do empty here instead of is_null
->hasHeader(...)also works instead of having to do the empty check.Alternatively you can do this:
->header(...)has a second parameter that can be specified as a default value when header is not present.Most of the time in Laravel when there's a "get" kind of function like this there's a secondary "default" parameter that defaults to null you can use, for example config(...), Arr::get(...), etc.