Skip to content

Commit 09fe564

Browse files
davidortinauCopilot
andcommitted
fix: Identity auth routing, antiforgery, and layout fixes
- Create AppRoutes.razor wrapper to include WebApp assembly in Blazor Router (Account pages in WebApp weren't discovered by UI-only Router) - Change account form POST endpoints to /account-action/* prefix to avoid collision with Blazor component routes that intercept form POSTs - Add <AntiforgeryToken /> to all account forms (Register, Login, Logout, ForgotPassword, ResetPassword) - Update LoginDisplay logout form to use /account-action/Logout path Tested: Register creates user in DB, auto-signs in, redirects to dashboard. Login page renders correctly with authenticated state shown in LoginDisplay. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a9d0e8a commit 09fe564

File tree

8 files changed

+27
-7
lines changed

8 files changed

+27
-7
lines changed

src/SentenceStudio.WebApp/Auth/AccountEndpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class AccountEndpoints
99
{
1010
public static void MapAccountEndpoints(this WebApplication app)
1111
{
12-
var group = app.MapGroup("/Account");
12+
var group = app.MapGroup("/account-action");
1313

1414
group.MapPost("/Login", async (
1515
[FromForm] string email,

src/SentenceStudio.WebApp/Components/App.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<body>
2121
<CascadingAuthenticationState>
22-
<SentenceStudio.WebUI.Routes @rendermode="InteractiveServer" />
22+
<SentenceStudio.WebApp.Components.AppRoutes @rendermode="InteractiveServer" />
2323
</CascadingAuthenticationState>
2424
<ReconnectModal />
2525
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Router AppAssembly="typeof(SentenceStudio.WebUI.Routes).Assembly"
2+
AdditionalAssemblies="new[] { typeof(AppRoutes).Assembly }">
3+
<Found Context="routeData">
4+
<RouteView RouteData="routeData" DefaultLayout="typeof(SentenceStudio.WebUI.Layout.MainLayout)" />
5+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
6+
</Found>
7+
<NotFound>
8+
<LayoutView Layout="typeof(SentenceStudio.WebUI.Layout.MainLayout)">
9+
<div class="container text-center mt-5">
10+
<h1>Page not found</h1>
11+
<p class="text-secondary">Sorry, the page you requested could not be found.</p>
12+
</div>
13+
</LayoutView>
14+
</NotFound>
15+
</Router>

src/SentenceStudio.WebApp/Components/Layout/LoginDisplay.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
}
2020
else
2121
{
22-
<form method="post" action="/Account/Logout" class="d-inline">
22+
<form method="post" action="/account-action/Logout" class="d-inline">
23+
<AntiforgeryToken />
2324
<button type="submit" class="btn btn-outline-light btn-sm">
2425
<i class="bi bi-box-arrow-right me-1"></i>Sign out
2526
</button>

src/SentenceStudio.WebApp/Components/Pages/Account/ForgotPassword.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
Enter your email address and we will send you a link to reset your password.
2626
</p>
2727

28-
<form method="post" action="/Account/ForgotPassword">
28+
<form method="post" action="/account-action/ForgotPassword">
29+
<AntiforgeryToken />
2930
<div class="mb-3">
3031
<label for="email" class="form-label">Email</label>
3132
<input type="email" class="form-control" id="email" name="email"

src/SentenceStudio.WebApp/Components/Pages/Account/Login.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<div class="alert alert-success" role="alert">@SuccessMessage</div>
2121
}
2222

23-
<form method="post" action="/Account/Login">
23+
<form method="post" action="/account-action/Login">
24+
<AntiforgeryToken />
2425
<input type="hidden" name="returnUrl" value="@ReturnUrl" />
2526

2627
<div class="mb-3">

src/SentenceStudio.WebApp/Components/Pages/Account/Register.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
</div>
2323
}
2424

25-
<form method="post" action="/Account/Register">
25+
<form method="post" action="/account-action/Register">
26+
<AntiforgeryToken />
2627
<div class="mb-3">
2728
<label for="displayName" class="form-label">Display Name</label>
2829
<input type="text" class="form-control" id="displayName" name="displayName"

src/SentenceStudio.WebApp/Components/Pages/Account/ResetPassword.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<div class="alert alert-danger" role="alert">@ErrorMessage</div>
1616
}
1717

18-
<form method="post" action="/Account/ResetPassword">
18+
<form method="post" action="/account-action/ResetPassword">
19+
<AntiforgeryToken />
1920
<input type="hidden" name="email" value="@Email" />
2021
<input type="hidden" name="token" value="@Token" />
2122

0 commit comments

Comments
 (0)