Middleware se encarga de validar que usuario pertenezca al restaurant

This commit is contained in:
2021-07-20 02:03:29 -04:00
parent 3534fdd02a
commit 6a7e08478f
9 changed files with 112 additions and 86 deletions

View File

@@ -17,12 +17,20 @@ class Auth0Middleware {
$token = $request->bearerToken();
if (!$token) {
Log::warning('Se intento acceder a una ruta protegida sin un token', [
'path' => $request->getPathInfo()
]);
return response()->json(['error' => 'no_token', 'message' => 'No se envío el token'], 401);
}
try {
$validated = $this->validateToken($token);
} catch (InvalidTokenException $e) {
Log::warning('Se intento acceder a una ruta protegida con un token invalido', [
'path' => $request->getPathInfo(),
'message' => $e->getMessage(),
'token' => $token
]);
return response()->json([
'error' => 'auth0_invalid_token',
'message' => $e->getMessage()
@@ -30,6 +38,7 @@ class Auth0Middleware {
}
$user = Usuario::where('auth0_id', $validated['sub'])->first();
Log::debug('Se identifico al usuario', ['id' => $user->id, 'auth0_id' => $user->auth0_id]);
return $next($request->merge(['user' => $user]));
}