Spaces:
Sleeping
Sleeping
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 |
-
|
| 35 |
-
var user = await _userRepo.
|
| 36 |
if (user == null)
|
| 37 |
{
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
{
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 });
|