Skip to content

Commit 5046c4b

Browse files
committed
feat(api): add response metadata to anonymous auth endpoint
Standardizes the success response for the anonymous sign-in 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 ece92ee commit 5046c4b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

routes/api/v1/auth/anonymous.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:dart_frog/dart_frog.dart';
44
import 'package:ht_api/src/services/auth_service.dart';
55
import 'package:ht_shared/ht_shared.dart';
66

7+
import '../../../_middleware.dart';
8+
79
/// Handles POST requests to `/api/v1/auth/anonymous`.
810
///
911
/// Creates a new anonymous user and returns the User object along with an
@@ -27,11 +29,16 @@ Future<Response> onRequest(RequestContext context) async {
2729
token: result.token,
2830
);
2931

32+
// Create metadata, including the requestId from the context.
33+
final metadata = ResponseMetadata(
34+
requestId: context.read<RequestId>().id,
35+
timestamp: DateTime.now().toUtc(),
36+
);
37+
3038
// Wrap the payload in the standard SuccessApiResponse
3139
final responsePayload = SuccessApiResponse<AuthSuccessResponse>(
3240
data: authPayload,
33-
// Optionally add metadata if needed/available
34-
// metadata: ResponseMetadata(timestamp: DateTime.now().toUtc()),
41+
metadata: metadata,
3542
);
3643

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

0 commit comments

Comments
 (0)