Skip to content

feat(AUTH, USER): ajouter la fonctionnalité de suppression de compte utilisateur#71

Merged
rom98759 merged 2 commits intocodastream:mainfrom
rom98759:delete-user
Feb 12, 2026
Merged

feat(AUTH, USER): ajouter la fonctionnalité de suppression de compte utilisateur#71
rom98759 merged 2 commits intocodastream:mainfrom
rom98759:delete-user

Conversation

@rom98759
Copy link
Collaborator

Ajouter les routes pour delete user depuis le service auth qui call user et redis pour supprimer en cascade

Route delete user :
api/auth/user/delete

Delete son propre user

Admin :
api/auth/users/:id

peut delete n'importe quel user

Copy link
Collaborator Author

@rom98759 rom98759 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good pour moi 👍🏼

@rom98759 rom98759 self-assigned this Feb 11, 2026
@rom98759 rom98759 added the feature New feature or request label Feb 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a “delete user account” flow across the microservices: auth orchestrates the deletion (users-service profile + Redis online state + auth DB), and users exposes an internal endpoint to delete a profile by userId.

Changes:

  • Users-service: add DELETE /users/:userId endpoint and service/controller method to delete a profile by auth/user id.
  • Auth-service: add DELETE /user/delete route + handler and implement authService.deleteUser() to cascade delete across UM + Redis + auth DB.
  • Auth-service: add UM client method to call users-service deletion, add Redis cleanup helper, and add rate limit config for delete.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
srcs/users/src/services/profiles.service.ts Adds deleteById() for profile deletion by numeric id.
srcs/users/src/routes/profiles.routes.ts Registers new internal DELETE /users/:userId route + Zod schema.
srcs/users/src/controllers/profiles.controller.ts Adds controller handler for deletion by id (204).
srcs/auth/src/utils/constants.ts Adds rate-limit config bucket for delete-user route.
srcs/auth/src/services/online.service.ts Adds Redis cleanup helper for removing a user’s online presence.
srcs/auth/src/services/external/um.service.ts Adds deleteUserProfile() call to users-service via mTLS fetch.
srcs/auth/src/services/auth.service.ts Adds orchestrated deleteUser() cascade delete implementation.
srcs/auth/src/routes/auth.routes.ts Exposes DELETE /user/delete route with rate limiting.
srcs/auth/src/controllers/auth.controller.ts Adds deleteUserHandler for self-account deletion.
srcs/auth/src/controllers/admin.controller.ts Switches admin deletion to use the new cascade authService.deleteUser().

Comment on lines +251 to +274
export async function removeUserFromRedis(userId: number): Promise<void> {
try {
const client = getRedisClient();
const userKey = `${ONLINE_KEY_PREFIX}${userId}`;

// Supp user online key
await client.del(userKey);

// Supp user du set des utilisateurs en ligne
await client.srem(ONLINE_USERS_SET, userId.toString());

logger.info({
event: 'user_redis_cleanup',
userId,
message: 'User data removed from Redis',
});
} catch (error) {
logger.error({
event: 'user_redis_cleanup_error',
userId,
error: (error as Error)?.message,
});
throw error;
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operationally, failing Redis cleanup currently aborts account deletion because this function rethrows. Since online status is ephemeral and other Redis reads (e.g. isUserOnline) degrade gracefully on Redis errors, consider making removeUserFromRedis best-effort (log + continue) or returning a typed error that deleteUser can treat as non-blocking.

Copilot uses AI. Check for mistakes.
Copy link
Owner

@codastream codastream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

les PR courtes sont effectivement + simples à suivre et c'est bien d'avoir les suppressions en cascade (profile et redis)
il y a peut-être moyen de mutualiser du code (checks sur user pour les routes avec auth), voire de throw AppError & laisser faire errorHandler pour raccourcir les controllers et services

logger.info({ msg: `user profile deleted successfully`, userId });
} catch (error) {
logger.error({ msg: `error DELETE ${UM_SERVICE_URL}/users/${userId}`, error: error });
if (error instanceof ServiceError) throw error;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on peut utiliser AppError : c'était trop de distinguer les DataError et ServiceError

},
} as const;

const deleteProfileByIdSchema = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rom98759 rom98759 merged commit 658d780 into codastream:main Feb 12, 2026
7 of 8 checks passed
@rom98759 rom98759 deleted the delete-user branch February 12, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants