fix(unit-2-auth): Redirect to /setup on API failure; store owner display name
- Router catch block now falls back to { initialized: false } instead of
silently continuing, preventing unwanted redirect to /login when the
API call fails at startup
- Add Name field to CreateOwnerRequest and propagate to ApplicationUser.DisplayName
so the owner's display name is stored during initial setup
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,9 +91,11 @@ const rootRoute = createRootRouteWithContext<RouterContext>()({
|
|||||||
let status: SetupStatus;
|
let status: SetupStatus;
|
||||||
try {
|
try {
|
||||||
status = await fetchSetupStatus();
|
status = await fetchSetupStatus();
|
||||||
} catch {
|
} catch (err) {
|
||||||
// Network failure — let routes render; API calls will surface errors.
|
// On network failure, assume not initialized so the user can set up
|
||||||
return;
|
// the system once the backend is reachable. Logging helps debugging.
|
||||||
|
console.warn('[InitGuard] Setup status check failed, assuming not initialized:', err);
|
||||||
|
status = { initialized: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSetup = location.pathname === '/setup';
|
const onSetup = location.pathname === '/setup';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace SlpModularCms.Core.Identity.Models;
|
namespace SlpModularCms.Core.Identity.Models;
|
||||||
|
|
||||||
public record CreateOwnerRequest(string Email, string Password);
|
public record CreateOwnerRequest(string Name, string Email, string Password);
|
||||||
public record LoginRequest(string Email, string Password);
|
public record LoginRequest(string Email, string Password);
|
||||||
public record InviteUserRequest(string Email, string Role);
|
public record InviteUserRequest(string Email, string Role);
|
||||||
public record CompleteSetupRequest(string Token, string Password);
|
public record CompleteSetupRequest(string Token, string Password);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace SlpModularCms.Core.Identity.Services;
|
|||||||
public interface ISetupService
|
public interface ISetupService
|
||||||
{
|
{
|
||||||
Task<bool> IsSystemInitializedAsync();
|
Task<bool> IsSystemInitializedAsync();
|
||||||
Task CreateInitialOwnerAsync(string email, string password);
|
Task CreateInitialOwnerAsync(string name, string email, string password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SetupService : ISetupService
|
public class SetupService : ISetupService
|
||||||
@@ -27,7 +27,7 @@ public class SetupService : ISetupService
|
|||||||
return await _userManager.Users.AnyAsync();
|
return await _userManager.Users.AnyAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateInitialOwnerAsync(string email, string password)
|
public async Task CreateInitialOwnerAsync(string name, string email, string password)
|
||||||
{
|
{
|
||||||
if (await IsSystemInitializedAsync())
|
if (await IsSystemInitializedAsync())
|
||||||
{
|
{
|
||||||
@@ -48,6 +48,7 @@ public class SetupService : ISetupService
|
|||||||
{
|
{
|
||||||
UserName = email,
|
UserName = email,
|
||||||
Email = email,
|
Email = email,
|
||||||
|
DisplayName = name,
|
||||||
IsActive = true
|
IsActive = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class SetupController : ControllerBase
|
|||||||
[HttpPost("owner")]
|
[HttpPost("owner")]
|
||||||
public async Task<IActionResult> CreateOwner([FromBody] CreateOwnerRequest request)
|
public async Task<IActionResult> CreateOwner([FromBody] CreateOwnerRequest request)
|
||||||
{
|
{
|
||||||
await _setupService.CreateInitialOwnerAsync(request.Email, request.Password);
|
await _setupService.CreateInitialOwnerAsync(request.Name, request.Email, request.Password);
|
||||||
return Ok(new { Message = "Systeem succesvol geïnitialiseerd. De eerste eigenaar is aangemaakt." });
|
return Ok(new { Message = "Systeem succesvol geïnitialiseerd. De eerste eigenaar is aangemaakt." });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user