@@ -2,7 +2,8 @@ import 'dart:io';
22
33import 'package:dart_frog/dart_frog.dart' ;
44import 'package:ht_api/src/services/auth_service.dart' ;
5- import 'package:ht_shared/ht_shared.dart' ; // For exceptions and models
5+ // Import exceptions, User, SuccessApiResponse, AND AuthSuccessResponse
6+ import 'package:ht_shared/ht_shared.dart' ;
67
78/// Handles POST requests to `/api/v1/auth/anonymous` .
89///
@@ -21,12 +22,23 @@ Future<Response> onRequest(RequestContext context) async {
2122 // Call the AuthService to handle anonymous sign-in logic
2223 final result = await authService.performAnonymousSignIn ();
2324
24- // Return 200 OK with the user and token
25+ // Create the specific payload containing user and token
26+ final authPayload = AuthSuccessResponse (
27+ user: result.user,
28+ token: result.token,
29+ );
30+
31+ // Wrap the payload in the standard SuccessApiResponse
32+ final responsePayload = SuccessApiResponse <AuthSuccessResponse >(
33+ data: authPayload,
34+ // Optionally add metadata if needed/available
35+ // metadata: ResponseMetadata(timestamp: DateTime.now().toUtc()),
36+ );
37+
38+ // Return 200 OK with the standardized, serialized response
2539 return Response .json (
26- body: {
27- 'user' : result.user.toJson (), // Serialize the User object
28- 'token' : result.token,
29- },
40+ // Use the toJson method, providing the toJson factory for the inner type
41+ body: responsePayload.toJson ((authSuccess) => authSuccess.toJson ()),
3042 );
3143 } on HtHttpException catch (_) {
3244 // Let the central errorHandler middleware handle known exceptions
0 commit comments