I'm using Laravel for backend and AngularJS for handle the front-end. The problem is the angularjs call ajax to controller to get the data, otherwise the auth middleware, i want to add 1 more middleware called apiKeyAuth to check if end user send request with valid api key. But after i check the conditional inside apiKeyAuth, it give me an error in \Http\Middleware\VerifyCsrfToken.php. The return type of invalid api key is an array. Below is my code.
*APIKeyAuth Middleware:
class APIKeyAuth
{
public function handle($request, Closure $next)
{
if ($request->get('api_key') != 'MyAPIKey'){
return ['status' => 401, 'message' => 'Invalid API Key.', 'data' => null];
}
return $next($request);
}
}