Skip to content

Commit fe9055d

Browse files
committed
feat(api): add response metadata to verify-code endpoint
Standardizes the success response for the verify-code endpoint by including the `ResponseMetadata` object, which contains the `requestId` and a timestamp. This ensures that all successful authentication responses that return a body are structured consistently, improving API uniformity.
1 parent 5046c4b commit fe9055d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

routes/api/v1/auth/verify-code.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import 'package:ht_api/src/services/auth_service.dart';
55
// Import exceptions, User, SuccessApiResponse, AND AuthSuccessResponse
66
import 'package:ht_shared/ht_shared.dart';
77

8+
import '../../../_middleware.dart';
9+
810
/// Handles POST requests to `/api/v1/auth/verify-code`.
911
///
1012
/// Verifies the provided email and code, completes the sign-in/sign-up,
@@ -84,11 +86,16 @@ Future<Response> onRequest(RequestContext context) async {
8486
token: result.token,
8587
);
8688

89+
// Create metadata, including the requestId from the context.
90+
final metadata = ResponseMetadata(
91+
requestId: context.read<RequestId>().id,
92+
timestamp: DateTime.now().toUtc(),
93+
);
94+
8795
// Wrap the payload in the standard SuccessApiResponse
8896
final responsePayload = SuccessApiResponse<AuthSuccessResponse>(
8997
data: authPayload,
90-
// Optionally add metadata if needed/available
91-
// metadata: ResponseMetadata(timestamp: DateTime.now().toUtc()),
98+
metadata: metadata,
9299
);
93100

94101
// Return 200 OK with the standardized, serialized response

0 commit comments

Comments
 (0)