Skip to content

Commit 9d51a19

Browse files
admin ui working
1 parent a3cdcec commit 9d51a19

6 files changed

Lines changed: 54 additions & 11 deletions

File tree

ECommerce.AdminUI/Filters/AuthenticationFilter.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,51 @@ public void OnPageHandlerSelected(PageHandlerSelectedContext context)
1313

1414
public void OnPageHandlerExecuting(PageHandlerExecutingContext context)
1515
{
16+
var httpContext = context.HttpContext;
17+
18+
logger.LogDebug("AuthFilter: Page: {Page}, PathBase: {PathBase}, Path: {Path}",
19+
context.HandlerInstance?.GetType().Name,
20+
httpContext.Request.PathBase,
21+
httpContext.Request.Path);
22+
1623
// Skip authentication check for Login page to avoid infinite redirect loop
1724
// Also skip for HealthCheck endpoint used by Kubernetes probes
1825
if (context.HandlerInstance is Pages.LoginModel or Pages.HealthCheckModel)
1926
{
27+
logger.LogDebug("AuthFilter: Skipping auth check for login/health page");
2028
return;
2129
}
2230

23-
var httpContext = context.HttpContext;
31+
// Try to get token from session
2432
var token = httpContext.Session.GetString("AuthToken");
2533

34+
// Log session ID and token for debugging
35+
logger.LogDebug("AuthFilter: Session ID: {SessionID}, Token present: {HasToken}, CookieCount: {CookieCount}",
36+
httpContext.Session.Id,
37+
!string.IsNullOrEmpty(token),
38+
httpContext.Request.Cookies?.Count ?? 0);
39+
2640
if (!string.IsNullOrEmpty(token))
2741
{
42+
logger.LogDebug("AuthFilter: User authenticated with token, allowing access");
2843
return;
2944
}
3045

3146
logger.LogInformation("Unauthenticated access attempt to {Path}", httpContext.Request.PathBase + httpContext.Request.Path);
3247

33-
// Build the login URL with the correct path base
34-
var loginPath = httpContext.Request.PathBase.Add("/Login").ToString();
48+
// Build the login URL with the correct path base using string concatenation
49+
string loginPath;
50+
if (!string.IsNullOrEmpty(httpContext.Request.PathBase))
51+
{
52+
// Make sure we don't end up with double slashes
53+
loginPath = $"{httpContext.Request.PathBase}/Login";
54+
}
55+
else
56+
{
57+
loginPath = "/Login";
58+
}
59+
60+
logger.LogDebug("AuthFilter: Redirecting to {LoginPath}", loginPath);
3561
context.Result = new RedirectResult(loginPath);
3662
}
3763

ECommerce.AdminUI/Pages/Login.cshtml.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@ public LoginModel(AuthService authService, ILogger<LoginModel> logger)
2020
[Required(ErrorMessage = "Username is required")]
2121
public string Username { get; set; } = string.Empty;
2222

23-
public void OnGet()
23+
public IActionResult OnGet()
2424
{
25+
_logger.LogDebug("OnGet: Login page accessed. PathBase: {PathBase}, Path: {Path}, HasToken: {HasToken}",
26+
Request.PathBase, Request.Path, !string.IsNullOrEmpty(HttpContext.Session.GetString("AuthToken")));
27+
2528
// If already logged in, redirect to dashboard
2629
if (!string.IsNullOrEmpty(HttpContext.Session.GetString("AuthToken")))
2730
{
28-
// Use relative path without leading slash to respect PathBase
29-
Response.Redirect("Index");
31+
_logger.LogDebug("User has token, redirecting to Index");
32+
// Use RedirectToPage instead of Response.Redirect for more reliable path handling
33+
return RedirectToPage("Index");
3034
}
35+
36+
return Page();
3137
}
3238

3339
public async Task<IActionResult> OnPostAsync()
3440
{
41+
_logger.LogDebug("OnPostAsync: Login form submitted. Username: {Username}", Username);
42+
3543
if (!ModelState.IsValid)
3644
{
3745
return Page();
@@ -41,6 +49,7 @@ public async Task<IActionResult> OnPostAsync()
4149
{
4250
// Call the token generation API
4351
var token = await _authService.GenerateTokenAsync(Username);
52+
_logger.LogDebug("Token generation result: {TokenResult}", string.IsNullOrEmpty(token) ? "Failed" : "Success");
4453

4554
if (string.IsNullOrEmpty(token))
4655
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: admin-ui-config
5+
data:
6+
ModularMonolithApiUrl: "http://modularmonolith-service:8080/modulith"
7+
TokenServiceUrl: "http://modularmonolith-service:8080"
8+

ECommerce.AdminUI/k8s/base/dataprotection-pvc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ metadata:
44
name: dataprotection-pvc
55
spec:
66
accessModes:
7-
- ReadWriteOnce
7+
- ReadWriteOnce # Changed from ReadWriteMany to be compatible with local-path
88
resources:
99
requests:
10-
storage: 1Gi
11-
storageClassName: local-path
10+
storage: 100Mi
11+
storageClassName: local-path # Explicitly specify the storage class

ECommerce.AdminUI/k8s/base/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ metadata:
1515
labels:
1616
app: admin-ui
1717
spec:
18-
replicas: 2
18+
replicas: 1
1919
selector:
2020
matchLabels:
2121
app: admin-ui

ECommerce.AdminUI/k8s/overlays/dev/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resources:
88

99
replicas:
1010
- name: admin-ui
11-
count: 2
11+
count: 1
1212

1313
patches:
1414
- path: configmap.yaml

0 commit comments

Comments
 (0)