I'm having a middleware problem when I run my app in GAE. This is responsible for performing a basic validation in queries to my api. What it basically does is take an "api_token" that is sent in the header of each query and checks if it corresponds to any user. If it is NOT valid, it returns a 401 code with a text "Not authorized". The strange thing is that it works correctly locally but on the server it always returns 401. Analyzing the behavior a bit, apparently the token query to the db does not return any user. Below I leave some tests that I did, by which I show that the user exists, the token is being sent in the header and corresponds to the same one stored in the db.
Middleware:
public function handle($request, Closure $next)
{
$user = User::where('api_token', $request->header('api_token'))->first();
if ($user === null) {
return response()->json ('No autorizado', 401);
}
return $next($request);
}
Apparently $user is always null.
Request capture from the browser:
Capture request and response from Postman:
User capture with its corresponding api_token in the DB:
Important: There is NO connection problem with the DB, if I disable the middleware for the routes the queries work perfectly. Thank you very much in advance, greetings.