Skip to content

Commit 59297c5

Browse files
committed
fix(api): add credentials header to cors error responses
The errorHandler middleware was missing the `Access-Control-Allow-Credentials` header in its CORS configuration. This caused browsers to block credentialed requests (e.g., those with an Authorization header) that resulted in an error, leading to a specific CORS failure. This change adds the `Access-Control-Allow-Credentials: true` header to all error responses when the origin is allowed, resolving the issue and allowing the client to correctly read API error messages for authenticated or credentialed requests.
1 parent 5f43537 commit 59297c5

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/src/middlewares/error_handler.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Response _jsonErrorResponse({
127127

128128
if (isOriginAllowed) {
129129
headers[HttpHeaders.accessControlAllowOriginHeader] = requestOrigin;
130+
headers[HttpHeaders.accessControlAllowCredentialsHeader] = 'true';
130131
headers[HttpHeaders.accessControlAllowMethodsHeader] =
131132
'GET, POST, PUT, DELETE, OPTIONS';
132133
headers[HttpHeaders.accessControlAllowHeadersHeader] =

0 commit comments

Comments
 (0)