fix/headerauth-crash-missing-header #19
@ -15,6 +15,10 @@ class HeaderAuth
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next): Response
|
public function handle(Request $request, Closure $next): Response
|
||||||
{
|
{
|
||||||
|
if (! $request->hasHeader('X-BOTAUTH')) {
|
||||||
|
|
|||||||
|
return response()
|
||||||
|
->json(["status" => false, "message" => "Unauthorized."], 401);
|
||||||
|
}
|
||||||
if (!hash_equals(config('bot.header_auth'), $request->header('X-BOTAUTH'))) {
|
if (!hash_equals(config('bot.header_auth'), $request->header('X-BOTAUTH'))) {
|
||||||
return response('Unauthorized', 401);
|
return response('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.