Conversation
Add registration, cookie-backed login, password changes, and sign-out. Protect user actions with the authenticated identity, store password hashes, and add the database migration and client auth state. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 279b2234-e59e-4a47-8f00-af458d7e565b
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The migration can fail on legacy username collisions, and authentication flows contain unresolved security and state-handling issues.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 6
Open (11)
Restrict the post-login return URL to this application · New Restrict the post-registration return URL to this application · New Deduplicate after the final username normalization · New Invalidate existing sessions when the password changes · New Enforce prism uniqueness atomically · New Do not mutate prism state through GET · New Do not replace rays with an empty list on add failure · New Only clear local authentication after logout succeeds · New Throttle password login attempts · New Describe the new-password maximum in the validation error · New Describe the password maximum in the validation error · New
What changed in this PR
Adds cookie-based user accounts and protects write operations while preserving public reads.
Changes:
- Adds registration, login, logout, password changes, and Blazor authentication state.
- Associates ray/prism writes with the authenticated user.
- Adds password storage and legacy-user migration support.
| File | Description |
|---|---|
| README.md | Documents accounts and .NET 10. |
| Beam.Shared/RegisterRequest.cs | Defines registration validation. |
| Beam.Shared/LoginRequest.cs | Defines login input. |
| Beam.Shared/ChangePasswordRequest.cs | Defines password-change validation. |
| Beam.Shared/AuthResult.cs | Defines authentication responses. |
| Beam.Server/Program.cs | Configures cookie authentication. |
| Beam.Server/Controllers/UserController.cs | Makes user lookup read-only. |
| Beam.Server/Controllers/RayController.cs | Protects ray creation and derives ownership. |
| Beam.Server/Controllers/PrismController.cs | Protects prism mutations and derives ownership. |
| Beam.Server/Controllers/FrequencyController.cs | Protects frequency creation. |
| Beam.Server/Controllers/AuthController.cs | Implements account endpoints. |
| Beam.Server/ClaimsPrincipalExtensions.cs | Extracts authenticated user IDs. |
| Beam.Data/Migrations/BeamContextModelSnapshot.cs | Updates the EF model snapshot. |
| Beam.Data/Migrations/20260916152802_AddUserPasswords.Designer.cs | Describes the migration model. |
| Beam.Data/Migrations/20260916152802_AddUserPasswords.cs | Migrates legacy users and passwords. |
| Beam.Data/BeamContext.cs | Configures username and password fields. |
| Beam.Client/Shared/UserLayout.razor | Shows authenticated profile navigation. |
| Beam.Client/Shared/RedirectToLogin.razor | Redirects protected routes. |
| Beam.Client/Shared/NavPanel.razor | Adds account navigation and logout. |
| Beam.Client/Services/DataService.cs | Tracks the authenticated user. |
| Beam.Client/Services/BeamAuthenticationStateProvider.cs | Provides Blazor authentication state. |
| Beam.Client/Services/BeamApiService.cs | Adds authentication API calls. |
| Beam.Client/Program.cs | Registers authorization services. |
| Beam.Client/Pages/Settings.razor | Adds password settings and logout. |
| Beam.Client/Pages/Register.razor | Adds account registration UI. |
| Beam.Client/Pages/RayList.razor | Uses authenticated usernames. |
| Beam.Client/Pages/RayItem.razor | Gates prism controls by authentication. |
| Beam.Client/Pages/RayInput.razor | Gates ray creation by authentication. |
| Beam.Client/Pages/Login.razor | Adds sign-in UI. |
| Beam.Client/Pages/FrequencyList.razor | Gates frequency creation. |
| Beam.Client/Beam.Client.csproj | Adds authorization dependencies. |
| Beam.Client/App.razor | Enables authorized route handling. |
| Beam.Client/_Imports.razor | Imports authentication types. |
Files not reviewed (1)
- Beam.Data/Migrations/20260916152802_AddUserPasswords.Designer.cs: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return; | ||
| } | ||
|
|
||
| navigation.NavigateTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "" : ReturnUrl); |
| return; | ||
| } | ||
|
|
||
| navigation.NavigateTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "" : ReturnUrl); |
Comment on lines
+31
to
+34
| migrationBuilder.Sql(@" | ||
| UPDATE [Users] | ||
| SET [Username] = LEFT([Username], 32) | ||
| WHERE LEN([Username]) > 32;"); |
Comment on lines
+132
to
+135
| user.PasswordHash = _passwordHasher.HashPassword(user, request.NewPassword); | ||
| await _context.SaveChangesAsync(); | ||
|
|
||
| await SignInAsync(user); |
Comment on lines
+33
to
+37
| var alreadyPrismed = _context.Prisms.Any(p => p.RayId == prism.RayId && p.UserId == userId.Value); | ||
|
|
||
| if (!alreadyPrismed) | ||
| { | ||
| _context.Add(new Data.Prism { RayId = prism.RayId, UserId = userId.Value }); |
Comment on lines
42
to
46
| var resp = await http.PostAsJsonAsync("api/Ray/Add", ray); | ||
|
|
||
| if (!resp.IsSuccessStatusCode) return new List<Ray>(); | ||
|
|
||
| return (await resp.Content.ReadFromJsonAsync<List<Ray>>()) ?? new List<Ray>(); |
| internal async Task Logout() | ||
| { | ||
| return (await http.GetFromJsonAsync<User>($"api/User/Get/{name}")) ?? new User(); | ||
| await http.PostAsync("api/Auth/Logout", null); |
Comment on lines
+56
to
+57
| [HttpPost("[action]")] | ||
| public async Task<ActionResult<AuthResult>> Login([FromBody] LoginRequest request) |
| public string CurrentPassword { get; set; } | ||
|
|
||
| [Required(ErrorMessage = "A new password is required.")] | ||
| [StringLength(128, MinimumLength = 8, ErrorMessage = "Passwords must be at least 8 characters.")] |
| public string Username { get; set; } | ||
|
|
||
| [Required(ErrorMessage = "A password is required.")] | ||
| [StringLength(128, MinimumLength = 8, ErrorMessage = "Passwords must be at least 8 characters.")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Validation
dotnet build Beam.Server/Beam.Server.csproj --no-incremental