Spaces:
Running
Running
Commit ·
8cdcc3a
1
Parent(s): 5b515c5
Fix: Check user email first in GetToken to prevent unique key violation in SQLite
Browse files30 unmodified lines31323334353435363738383940414243444546474840414243444546495051525354555657585930 unmodified lines [HttpGet("token")] public async Task<IActionResult> GetToken() { var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); var user = await _userRepo.GetByIdAsync(userId); // First check if the user exists by email to prevent Unique Index violations var user = await _userRepo.GetByEmailAsync("dan9228335@gmail.com"); if (user == null) { user = new User var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab"); // Check if the hardcoded ID is somehow already in use var existingById = await _userRepo.GetByIdAsync(userId); if (existingById != null) { user = existingById; } else { user = new User { Id = userId, Email = "dan9228335@gmail.com", DisplayName = "Dodikuser", PasswordHash = "", CreatedAt = DateTime.UtcNow }; await _userRepo.CreateAsync(user); Id = userId, Email = "dan9228335@gmail.com", DisplayName = "Dodikuser", PasswordHash = "", CreatedAt = DateTime.UtcNow }; await _userRepo.CreateAsync(user); } } var token = _tokenService.CreateToken(user); return Ok(new { token });FlowAPI/Controllers/AgentCanvasController.cs+20-10