From f5a7aabf42a67969baf6e307b3178e89c75a4716 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sat, 13 Jun 2026 20:15:41 -0400 Subject: [PATCH] fix: handle username conflict during user creation --- SharpbinV3.Server/Controllers/AuthController.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SharpbinV3.Server/Controllers/AuthController.cs b/SharpbinV3.Server/Controllers/AuthController.cs index 1467972..7734320 100644 --- a/SharpbinV3.Server/Controllers/AuthController.cs +++ b/SharpbinV3.Server/Controllers/AuthController.cs @@ -61,7 +61,19 @@ namespace SharpbinV3.Server.Controllers if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26) return BadRequest(new { success = false, message = "Display name should not exceed 26 characters." }); - var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName); + User user; + try + { + user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName); + } + catch (DbUpdateException) + { + if (await _userService.GetByUsername(request.Username) != null) + return Conflict(new { success = false, message = "Username already exists." }); + + throw; + } + if (!string.IsNullOrWhiteSpace(user.Email)) await _authService.SendEmailVerification(user);