auth use for websocket building

This commit is contained in:
2025-09-26 03:23:56 +02:00
parent 00c5c2bd63
commit 65146fce91
3 changed files with 4 additions and 10 deletions

View File

@@ -7,13 +7,6 @@ use axum::extract::{ws::{Message, WebSocket, WebSocketUpgrade}, State};
type HotelId = i32; // or i32 if you want numeric ids
/// Type alias: user_id → sender to that user
type UserMap = DashMap<i32, mpsc::UnboundedSender<Message>>;
/// hotel_id → users
type HotelMap = DashMap<i32, Arc<UserMap>>;
/// global map of all hotels
type WsMap = Arc<HotelMap>;
/// Type alias: user_id → sender to that user
#[derive(Clone)]

View File

@@ -13,7 +13,7 @@ pub fn utils_routes() -> Router<AppState> {
Router::new()
.route("/login", put(clean_auth_loging))
.route("/register", put(register_user))
.route("/ws/{hotel_id}/{user_id}", get(ws_handler))
.route("/ws/", get(ws_handler))
.route("/tokentest", put(token_tester))
//.with_state(state)

View File

@@ -7,7 +7,7 @@ use axum::response::IntoResponse;
//use futures_util::stream::stream::StreamExt;
use futures_util::{StreamExt, SinkExt};
use crate::utils::db_pool::{HotelPool,AppState};
use crate::utils::{auth::AuthClaims, db_pool::{AppState, HotelPool}};
@@ -89,9 +89,10 @@ async fn handle_socket(
}
pub async fn ws_handler(
AuthClaims {user_id, hotel_id,username}: AuthClaims,
ws: WebSocketUpgrade,
State(state): State<AppState>,
Path((hotel_id, user_id)): Path<(i32, i32)>,
//Path((hotel_id, user_id)): Path<(i32, i32)>,
) -> impl IntoResponse {
ws.on_upgrade(move |socket| handle_socket(socket, state, hotel_id, user_id))
}