@@ -2,7 +2,8 @@ import 'dart:io';
2
2
3
3
import 'package:dart_frog/dart_frog.dart' ;
4
4
import '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' ;
6
7
7
8
/// Handles POST requests to `/api/v1/auth/anonymous` .
8
9
///
@@ -21,12 +22,23 @@ Future<Response> onRequest(RequestContext context) async {
21
22
// Call the AuthService to handle anonymous sign-in logic
22
23
final result = await authService.performAnonymousSignIn ();
23
24
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
25
39
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 ()),
30
42
);
31
43
} on HtHttpException catch (_) {
32
44
// Let the central errorHandler middleware handle known exceptions
0 commit comments