fipamo/app/Http/Middleware/ValidateAPIToken.php

30 lines
783 B
PHP
Raw Normal View History

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ValidateAPIToken
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$token = $request->header('fipamo-access-token');
if ($token == session('token')) {
return $next($request);
} else {
$response = [
'message' => "API Auth Fail",
'type' => 'postError',
];
return response()->json($response)->header('Content-Type', 'application/json');
}
}
}