added tracing per req and initial cookies
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 10m25s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 10m25s
This commit is contained in:
parent
02eb0d7cf5
commit
505100d930
57
Cargo.lock
generated
57
Cargo.lock
generated
@ -245,6 +245,17 @@ version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
|
||||
|
||||
[[package]]
|
||||
name = "cookie"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
"time",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
@ -510,6 +521,17 @@ version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.32"
|
||||
@ -530,6 +552,7 @@ checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
@ -1360,6 +1383,8 @@ dependencies = [
|
||||
"sqlx",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tower-cookies",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
@ -1993,6 +2018,38 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-cookies"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151b5a3e3c45df17466454bb74e9ecedecc955269bdedbf4d150dfa393b55a36"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"cookie",
|
||||
"futures-util",
|
||||
"http",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
|
||||
@ -22,3 +22,5 @@ uuid = { version = "1.23.1", features = ["serde", "v4"] }
|
||||
rand = "0.10.1"
|
||||
sha2 = "0.11.0"
|
||||
hex = "0.4.3"
|
||||
tower-cookies = "0.11.0"
|
||||
tower-http = { version = "0.6.8", features = ["trace"] }
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use axum::{Router, routing::get};
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
@ -9,4 +10,5 @@ pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/", get("Server is going brr 🚀"))
|
||||
.nest("/api/v1", v1::router_v1())
|
||||
.layer(TraceLayer::new_for_http())
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use axum::extract::State;
|
||||
use axum::{Json, Router, routing::post};
|
||||
use tower_cookies::{CookieManagerLayer, Cookies};
|
||||
|
||||
use crate::{
|
||||
controller::model::auth_model::{AuthResponse, LoginRequest, RegisterRequest},
|
||||
@ -12,17 +13,23 @@ pub fn auth_router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/login", post(login_handler))
|
||||
.route("/register", post(register_handler))
|
||||
.route("/refresh", post(refresh_handler))
|
||||
.layer(CookieManagerLayer::new())
|
||||
}
|
||||
|
||||
async fn login_handler(
|
||||
State(s): State<AppState>,
|
||||
cookies: Cookies,
|
||||
Json(payload): Json<LoginRequest>,
|
||||
) -> Result<Json<AuthResponse>, AppError> {
|
||||
login(&s, payload).await
|
||||
login(&s, cookies, payload).await
|
||||
}
|
||||
async fn register_handler(
|
||||
State(s): State<AppState>,
|
||||
cookies: Cookies,
|
||||
Json(payload): Json<RegisterRequest>,
|
||||
) -> Result<Json<AuthResponse>, AppError> {
|
||||
register(&s, payload).await
|
||||
register(&s, cookies, payload).await
|
||||
}
|
||||
|
||||
async fn refresh_handler(State(s): State<AppState>, cookies: Cookies) {}
|
||||
|
||||
@ -2,6 +2,7 @@ use std::time::Instant;
|
||||
|
||||
use axum::Json;
|
||||
use chrono::{Duration, Utc};
|
||||
use tower_cookies::{Cookie, Cookies};
|
||||
|
||||
use crate::controller::model::auth_model::*;
|
||||
use crate::db::repository::refresh_token_repository::create_refresh_token;
|
||||
@ -13,11 +14,16 @@ use crate::utils::hash;
|
||||
use crate::utils::jwt::generate_access_token;
|
||||
use crate::utils::refresh_token::generate_refresh_token;
|
||||
|
||||
pub async fn login(state: &AppState, req: LoginRequest) -> Result<Json<AuthResponse>, AppError> {
|
||||
pub async fn login(
|
||||
state: &AppState,
|
||||
cookies: Cookies,
|
||||
req: LoginRequest,
|
||||
) -> Result<Json<AuthResponse>, AppError> {
|
||||
todo!()
|
||||
}
|
||||
pub async fn register(
|
||||
state: &AppState,
|
||||
cookies: Cookies,
|
||||
req: RegisterRequest,
|
||||
) -> Result<Json<AuthResponse>, AppError> {
|
||||
let start = Instant::now();
|
||||
@ -46,3 +52,7 @@ pub async fn register(
|
||||
refresh_token: refresh_plain,
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn refresh(state: &AppState, cookies: Cookies) -> Result<(), AppError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user