Skip to content

Commit a12810b

Browse files
authored
disallow last conn del (#1716)
# Prevent users from deleting their last connection ## Description Added a validation check before deleting a connection to ensure users always maintain at least one connection. The system now throws an error if a user attempts to delete their last remaining connection. --- ## Type of Change - [x] 🐛 Bug fix (non-breaking change which fixes an issue) ## Areas Affected - [x] Data Storage/Management - [x] API Endpoints ## Testing Done - [x] Manual testing performed ## Security Considerations - [x] No sensitive data is exposed - [x] Input validation is implemented ## Checklist - [x] I have performed a self-review of my code - [x] My changes generate no new warnings ## Additional Notes This change prevents users from getting into a state where they have no connections, which could lead to unexpected behavior in the application. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._
1 parent 3ceab96 commit a12810b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

apps/server/src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ class ZeroDB extends DurableObject<Env> {
201201
}
202202

203203
async deleteConnection(connectionId: string, userId: string) {
204+
const connections = await this.findManyConnections(userId);
205+
if (connections.length <= 1) {
206+
throw new Error('Cannot delete the last connection. At least one connection is required.');
207+
}
204208
return await this.db
205209
.delete(connection)
206210
.where(and(eq(connection.id, connectionId), eq(connection.userId, userId)));

0 commit comments

Comments
 (0)