Skip to main content

login

Function login 

Source
pub async fn login(
    __arg0: State<DB>,
    __arg1: Json<LoginRequest>,
) -> (StatusCode, Json<AuthTokenResponse>)
Expand description

Handles user login requests

§Arguments

  • State(db) - Shared state containing the database connection and JWT configuration
  • Json(payload) - The login request payload containing username/email and password

§Returns

  • (StatusCode, Json<AuthTokenResponse>) - The HTTP status code and JSON response containing the authentication token or error message

§Error

  • StatusCode::UNAUTHORIZED - If the username/email or password is incorrect
  • StatusCode::INTERNAL_SERVER_ERROR - If there is an error verifying credentials, generating tokens, or storing the refresh token

§Example

let payload = LoginRequest {
    username_or_email: "user@example.com".to_string(),
    password: "password123".to_string(),
};