Skip to content

Commit 0a93674

Browse files
committed
feat(auth): update request-code handler to be context-aware
Modifies the `/api/v1/auth/request-code` route handler to parse an optional `is_dashboard_login` boolean field from the request body. This flag is then passed to the `AuthService.initiateEmailSignIn` method, enabling it to trigger the appropriate validation logic for either a standard user-facing app sign-in or a restricted dashboard login.
1 parent cca71a2 commit 0a93674

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import 'package:ht_shared/ht_shared.dart'; // For exceptions
77
/// Handles POST requests to `/api/v1/auth/request-code`.
88
///
99
/// Initiates the email sign-in process by requesting a verification code
10-
/// be sent to the provided email address.
10+
/// be sent to the provided email address. It supports a context-aware flow
11+
/// for dashboard logins by checking for an `is_dashboard_login` flag in the
12+
/// request body. If this flag is true, the `AuthService` will perform
13+
/// additional checks to ensure the user exists and has the required
14+
/// permissions before sending a code.
1115
Future<Response> onRequest(RequestContext context) async {
1216
// Ensure this is a POST request
1317
if (context.request.method != HttpMethod.post) {
@@ -37,6 +41,9 @@ Future<Response> onRequest(RequestContext context) async {
3741
);
3842
}
3943

44+
// Check for the optional dashboard login flag. Default to false if not present.
45+
final isDashboardLogin = (body['is_dashboard_login'] as bool?) ?? false;
46+
4047
// Basic email format check (more robust validation can be added)
4148
// Using a slightly more common regex pattern
4249
final emailRegex = RegExp(
@@ -48,8 +55,11 @@ Future<Response> onRequest(RequestContext context) async {
4855
}
4956

5057
try {
51-
// Call the AuthService to handle the logic
52-
await authService.initiateEmailSignIn(email);
58+
// Call the AuthService to handle the logic, passing the context flag.
59+
await authService.initiateEmailSignIn(
60+
email,
61+
isDashboardLogin: isDashboardLogin,
62+
);
5363

5464
// Return 202 Accepted: The request is accepted for processing,
5565
// but the processing (email sending) hasn't necessarily completed.

0 commit comments

Comments
 (0)