The login page atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Andrespeerez/porfolio-blog/llms.txt
Use this file to discover all available pages before exploring further.
/login is a Blazor Server component that renders a credential form, validates input with Data Annotations, delegates authentication to the AuthenticateUser use case, and navigates to /admin on success. The entire flow — validation, use-case call, navigation or error display — runs inside a single HandleLogin method wired to the form’s OnValidSubmit event.
Form model
The component defines a nestedLoginModel class that carries the form fields and their validation rules:
Login.razor (@code)
[Required] ensures neither field can be submitted empty. [EmailAddress] enforces a valid email format on the Email field (for example, user@example.com). Both attributes are standard System.ComponentModel.DataAnnotations decorators and are evaluated automatically by the <DataAnnotationsValidator> component inside the form — the form will not call HandleLogin until all validations pass.
The model instance is bound to the form via [SupplyParameterFromForm], which tells Blazor to populate the model from the HTTP form data on a static SSR POST:
Login.razor (@code)
Authentication logic
When the form passes validation, Blazor invokesHandleLogin:
Login.razor (@code)
Clear previous errors
error is reset to an empty string so stale error messages from a previous attempt are not shown.Call AuthenticateUser
AuthenticateUserUseCase.ExecuteAsync(email, password) looks up the user by email, verifies the password hash using IPasswordHasher, and — if credentials are valid — calls ISessionManager.SignInAsync() to write an authentication cookie to the response. It returns an AuthResult DTO with a Success boolean.Form rendering
The Razor markup renders the form using Blazor’s<EditForm> component:
Login.razor
| Element | Purpose |
|---|---|
<EditForm Model="model"> | Binds the form to the LoginModel instance and manages its EditContext |
OnValidSubmit="HandleLogin" | Fires HandleLogin only when all validation rules pass |
FormName="login" | Gives the form a stable name for Blazor’s static SSR form handling |
<DataAnnotationsValidator /> | Wires the EditContext to Data Annotations so [Required] and [EmailAddress] are enforced |
<ValidationSummary /> | Renders a consolidated list of all validation messages above the fields |
@bind-Value="model.Email" | Two-way binds the <InputText> to the Email property |
type="password" on the password <InputText> | Masks the input in the browser |
Login.razor (error display)
Injected dependencies
Login.razor declares two @inject directives at the top of the file:
Login.razor
Program.cs:
AuthenticateUser— registered asAddScoped<AuthenticateUser>(). It encapsulates the credential validation and session creation logic, keeping the page component free of infrastructure concerns.NavigationManager— a built-in Blazor service, always available without explicit registration, used to trigger the post-login redirect.
This page uses Blazor’s built-in form handling (
EditForm, OnValidSubmit). The HandleLogin method is only invoked when all Data Annotations validations pass — if Email is blank or malformed, or Password is empty, Blazor blocks submission and displays the validation messages via <ValidationSummary /> without ever calling HandleLogin.