Skip to content

Commit e7978b2

Browse files
committed
feat(auth): add validation for user creation in POST handler
Updates the _handlePost function in the generic data endpoint to include a specific validation check for modelName == 'user'. This ensures that any request to create a user includes a non-empty email field, preventing the creation of invalid user records.
1 parent 2ae6db4 commit e7978b2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

routes/api/v1/data/index.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ Future<Response> _handlePost(RequestContext context) async {
117117
throw const BadRequestException('Missing or invalid request body.');
118118
}
119119

120+
// For user creation, ensure the email field is present.
121+
if (modelName == 'user') {
122+
if (!requestBody.containsKey('email') ||
123+
(requestBody['email'] as String).isEmpty) {
124+
throw const BadRequestException('Missing required field: "email".');
125+
}
126+
}
127+
120128
final now = DateTime.now().toUtc().toIso8601String();
121129
requestBody['id'] = ObjectId().oid;
122130
requestBody['createdAt'] = now;

0 commit comments

Comments
 (0)