use crate::errors::AppError; use crate::models::{ auth::{AuthBody, Claims}, user::{User, UserCreate}, }; use axum::{routing::post, Json, Router}; pub fn create_route() -> Router { Router::new().route("/login", post(make_login)) } async fn make_login(Json(payload): Json) -> Result, AppError> { let user = User::new(payload.email, payload.password); match User::find(user).await { Ok(user) => { let claims = Claims::new(user.id); let token = claims.get_token()?; Ok(Json(AuthBody::new(token))) } Err(_) => Err(AppError::NotFound), } }