danylokhodus commited on
Commit
8cdcc3a
·
1 Parent(s): 5b515c5

Fix: Check user email first in GetToken to prevent unique key violation in SQLite

Browse files
FlowAPI/Controllers/AgentCanvasController.cs CHANGED
@@ -31,19 +31,29 @@ namespace FlowAPI.Controllers
31
  [HttpGet("token")]
32
  public async Task<IActionResult> GetToken()
33
  {
34
- var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
35
- var user = await _userRepo.GetByIdAsync(userId);
36
  if (user == null)
37
  {
38
- user = new User
 
 
 
39
  {
40
- Id = userId,
41
- Email = "dan9228335@gmail.com",
42
- DisplayName = "Dodikuser",
43
- PasswordHash = "",
44
- CreatedAt = DateTime.UtcNow
45
- };
46
- await _userRepo.CreateAsync(user);
 
 
 
 
 
 
 
47
  }
48
  var token = _tokenService.CreateToken(user);
49
  return Ok(new { token });
 
31
  [HttpGet("token")]
32
  public async Task<IActionResult> GetToken()
33
  {
34
+ // First check if the user exists by email to prevent Unique Index violations
35
+ var user = await _userRepo.GetByEmailAsync("dan9228335@gmail.com");
36
  if (user == null)
37
  {
38
+ var userId = Guid.Parse("33d1ae31-bf51-4b12-89d0-8e574e7916ab");
39
+ // Check if the hardcoded ID is somehow already in use
40
+ var existingById = await _userRepo.GetByIdAsync(userId);
41
+ if (existingById != null)
42
  {
43
+ user = existingById;
44
+ }
45
+ else
46
+ {
47
+ user = new User
48
+ {
49
+ Id = userId,
50
+ Email = "dan9228335@gmail.com",
51
+ DisplayName = "Dodikuser",
52
+ PasswordHash = "",
53
+ CreatedAt = DateTime.UtcNow
54
+ };
55
+ await _userRepo.CreateAsync(user);
56
+ }
57
  }
58
  var token = _tokenService.CreateToken(user);
59
  return Ok(new { token });