Skip to content

Commit 9a2b1e9

Browse files
committed
fix(auth): make request-code handler resilient to body param types
Refactors the parsing of the `isDashboardLogin` parameter in the `/api/v1/auth/request-code` route handler. Previously, the handler would crash with a type cast error if the `isDashboardLogin` value was sent as a string (e.g., `"true"`) instead of a boolean. This change introduces robust parsing that correctly handles values that are boolean `true`, the string `"true"`, or missing, preventing the 500 Internal Server Error and making the endpoint more resilient to varied client implementations.
1 parent ca36a5c commit 9a2b1e9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ Future<Response> onRequest(RequestContext context) async {
4343
);
4444
}
4545

46-
// Check for the optional dashboard login flag. Default to false if not present.
47-
final isDashboardLogin = (body['isDashboardLogin'] as bool?) ?? false;
46+
// Check for the optional dashboard login flag. This handles both boolean
47+
// `true` and string `"true"` values to prevent type cast errors.
48+
// It defaults to `false` if the key is missing or the value is not
49+
// recognized as true.
50+
final isDashboardLoginRaw = body['isDashboardLogin'];
51+
var isDashboardLogin = false;
52+
if (isDashboardLoginRaw is bool) {
53+
isDashboardLogin = isDashboardLoginRaw;
54+
} else if (isDashboardLoginRaw is String) {
55+
isDashboardLogin = isDashboardLoginRaw.toLowerCase() == 'true';
56+
}
4857

4958
// Basic email format check (more robust validation can be added)
5059
// Using a slightly more common regex pattern

0 commit comments

Comments
 (0)