Skip to content

Commit c9f42d8

Browse files
committed
refactor(api): simplify verify-link-email route with ResponseHelper
Updates the `/api/v1/auth/verify-link-email` route handler to use the new `ResponseHelper.success` method. This change removes several lines of boilerplate code related to manually creating metadata and the success response object, making the handler cleaner and more focused on its core logic.
1 parent e98c5fa commit c9f42d8

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

routes/api/v1/auth/verify-link-email.dart

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import 'dart:io';
22

33
import 'package:dart_frog/dart_frog.dart';
4+
import 'package:ht_api/src/helpers/response_helper.dart';
45
import 'package:ht_api/src/services/auth_service.dart';
56
import 'package:ht_shared/ht_shared.dart';
67

7-
import '../../../_middleware.dart';
8-
98
/// Handles POST requests to `/api/v1/auth/verify-link-email`.
109
///
1110
/// Allows an authenticated anonymous user to complete the email linking process
@@ -90,21 +89,11 @@ Future<Response> onRequest(RequestContext context) async {
9089
token: result.token,
9190
);
9291

93-
// Create metadata, including the requestId from the context.
94-
final metadata = ResponseMetadata(
95-
requestId: context.read<RequestId>().id,
96-
timestamp: DateTime.now().toUtc(),
97-
);
98-
99-
// Wrap the payload in the standard SuccessApiResponse
100-
final responsePayload = SuccessApiResponse<AuthSuccessResponse>(
92+
// Use the helper to create a standardized success response
93+
return ResponseHelper.success(
94+
context: context,
10195
data: authPayload,
102-
metadata: metadata,
103-
);
104-
105-
// Return 200 OK with the standardized, serialized response
106-
return Response.json(
107-
body: responsePayload.toJson((authSuccess) => authSuccess.toJson()),
96+
toJsonT: (data) => data.toJson(),
10897
);
10998
} on HtHttpException catch (_) {
11099
rethrow;

0 commit comments

Comments
 (0)