pub async fn login(
__arg0: State<Arc<AppState>>,
__arg1: Json<LoginScheme>,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)>Expand description
Authenticates a user and creates a JWT token for session management.
Verifies the provided username and password against stored credentials using Argon2 verification.
On successful authentication, generates and encodes a Claims token via encode_token and sets it as an HTTP-only cookie.
The token is valid for 1 hour.
§Arguments
State(data): Application state containingAppStatefor database accessrequest:LoginSchemecontaining login credentials (username, password)
§Returns
200 OKwith JSON containing token and filteredFilteredUserinfo400 Bad Requestif username not found or password invalid500 Internal Server Errorif database query fails
§Security Features
- HTTP-only cookie prevents JavaScript access
- SameSite=Lax protects against CSRF attacks
- Password verification uses Argon2 with stored
Userhash - JWT token includes user ID and expiration timestamp via
Claimsencoded byencode_token
§Example Response
{
"status": "success",
"token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"user": {"id": 1, "first_name": "Admin", "last_name": "User", "username": "admin", "is_admin": true}
}