Skip to content

Commit 183c828

Browse files
committed
feat(auth): update verify-code handler to be context-aware
Modifies the `/api/v1/auth/verify-code` route handler to parse an optional `is_dashboard_login` boolean field from the request body. This flag is passed to the `AuthService.completeEmailSignIn` method, enabling it to trigger the appropriate verification logic for either a standard user-facing app sign-in/sign-up or a restricted dashboard login. The handler is also simplified by removing the now-redundant logic for passing the `authenticatedUser` to the service.
1 parent 305388e commit 183c828

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ import 'package:ht_shared/ht_shared.dart';
88
/// Handles POST requests to `/api/v1/auth/verify-code`.
99
///
1010
/// Verifies the provided email and code, completes the sign-in/sign-up,
11-
/// and returns the authenticated User object along with an auth token.
11+
/// and returns the authenticated User object along with an auth token. It
12+
/// supports a context-aware flow by checking for an `is_dashboard_login`
13+
/// flag in the request body, which dictates whether to perform a strict
14+
/// login-only check or a standard sign-in/sign-up.
1215
Future<Response> onRequest(RequestContext context) async {
1316
// Ensure this is a POST request
1417
if (context.request.method != HttpMethod.post) {
1518
return Response(statusCode: HttpStatus.methodNotAllowed);
1619
}
1720

18-
// Read the AuthService provided by middleware
21+
// Read the AuthService provided by middleware.
22+
// The `authenticatedUser` is no longer needed here as the service handles
23+
// all context internally.
1924
final authService = context.read<AuthService>();
2025

21-
// Read the authenticated User from context (provided by authentication middleware)
22-
// This user might be null (if not authenticated) or an anonymous user.
23-
final authenticatedUser = context.read<User?>();
24-
2526
// Parse the request body
2627
final dynamic body;
2728
try {
@@ -65,13 +66,16 @@ Future<Response> onRequest(RequestContext context) async {
6566
);
6667
}
6768

69+
// Check for the optional dashboard login flag. Default to false.
70+
final isDashboardLogin = (body['is_dashboard_login'] as bool?) ?? false;
71+
6872
try {
6973
// Call the AuthService to handle the verification and sign-in logic
70-
// Pass the current authenticated user for potential data migration.
74+
// Pass the context flag to determine the correct flow.
7175
final result = await authService.completeEmailSignIn(
7276
email,
7377
code,
74-
currentAuthUser: authenticatedUser,
78+
isDashboardLogin: isDashboardLogin,
7579
);
7680

7781
// Create the specific payload containing user and token

0 commit comments

Comments
 (0)