Week 13: User deletion feature
Tymur Levtsun
Posted on April 18, 2023
Overview
As we wrap up week 13, we are inching closer to the launch of StartChart (aka MyCustomDomain) 1.0. Despite a busy week with school submissions, I managed to implement a crucial feature: user deletion, available exclusively for admins.
Problem Statement
Deleting a user in a system often requires cascading deletion of all or most data associated with them. StartChart is no exception; our users have DNS records that need to be deleted as well. However, we decided not to delete SSL certificates for security reasons or other considerations.
Implementation
Surprisingly, I didn't need to write any cascading deletion functionality myself. Prisma handles it automatically by deleting all entities referencing the deleted user, like DNS records in a many-to-one relationship. This revelation was quite impressive for me.
User deletion boiled down to two lines of code:
- Deleting the user from the database (it cascades to DNS records)
- Setting the reconciler to reconcile the database with Route53
Here's the code snippet:
export async function deleteUser(username: User['username']) {
await deleteUserByUsername(username);
return setIsReconciliationNeeded(true);
}
The bigger issue was to integrate it in existing admin page. There were 2 type of actions before I added user deletion:
- Searching users
- Impersonating users
With the addition of the third action, I refactored the code and assigned an intent
to each action, which I believe is the recommended way to handle multiple actions in Remix. I also updated the zod schema and made some fields optional for reuse across different actions.
Review
After I was done, created the PR and few iterations of reviews with minor suggestions it ended up being merged.
https://github.com/DevelopingSpace/starchart/pull/607
Afterthoughts
Last week was tough as I had to catch up with classes and submit various projects. Fortunately, I managed to do so successfully. It was also an Orthodox Easter and even tho I am consider myself as atheist, it was a very great time spent with my family that I really appreciated. I also signed up for the olympic distance triathlon that gonna be in the late July, and I feel like this is gonna be amazing (fun fact: I newer swam in pool for more than 50 meters and don't have a bike yet). Right now I just gotta do a final stretch and school is gonna be done, I am a one week closer to lifestyle I want to have.
Oh, and also the last thing, I tried cold-showering for one minute in the morning (after like 10 mins of the warm shower as I usually have + going out for like 10 minutes right after that = feeling amazing and energetic throughout the day. Good luck with finals, everyone! Peace.
Posted on April 18, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024