diff --git a/db/1.sqlite-shm b/db/1.sqlite-shm index dd83caa..73b6945 100644 Binary files a/db/1.sqlite-shm and b/db/1.sqlite-shm differ diff --git a/db/auth_copy_2.sqlite-wal b/db/auth_copy_2.sqlite-wal index 17b4465..c3cb572 100644 Binary files a/db/auth_copy_2.sqlite-wal and b/db/auth_copy_2.sqlite-wal differ diff --git a/src/utils/auth.rs b/src/utils/auth.rs index 7fadaab..20947c3 100644 --- a/src/utils/auth.rs +++ b/src/utils/auth.rs @@ -781,12 +781,12 @@ pub async fn logout_from_all_devices ( State(state): State, Extension(keys): Extension, AuthClaims { user_id, hotel_id }: AuthClaims, - Json(payload): Json + //Json(payload): Json ) -> impl IntoResponse { - let device_id_str = payload.device_id.to_string(); + //let device_id_str = payload.device_id.to_string(); let conn = match state.logs_pool.get() { Ok(c) => c, @@ -794,23 +794,48 @@ pub async fn logout_from_all_devices ( }; let result = conn.execute( - "UPDATE refresh_token SET revoked = 1 WHERE user_id = ?1 AND revoked = 0", + "DELETE FROM refresh_token WHERE user_id = ?1", params![&user_id], ); + /* + match result { - Ok(count) if count > 0 => { - (StatusCode::OK, format!("Revoked {} active tokens", count)).into_response() - } - Ok(_) => (StatusCode::NOT_FOUND, "No active tokens to revoke").into_response(), + //Ok(count) if count > 0 => { + // (StatusCode::OK, format!("Revoked {} active tokens", count)).into_response() + //} + //Ok(_) => (StatusCode::NOT_FOUND, "No active tokens to revoke").into_response(), Err(_) => ( StatusCode::INTERNAL_SERVER_ERROR, "Database update error".to_string(), ) .into_response(), } + */ + let cookie_value = format!("refresh_token={}; HttpOnly; Secure; Max-Age=0;Path=/", "loggedout"); + + let mut response = (StatusCode::CREATED, format!("Token deleted for device id ")) + .into_response(); + + response.headers_mut().insert( + SET_COOKIE, + HeaderValue::from_str(&cookie_value).unwrap(), + ); + + match result { + //Ok(count) if count > 0 => { + // (StatusCode::OK, format!("Revoked {} active tokens", count)).into_response() + //} + Ok(_) => response, + Err(err) => ( + StatusCode::INTERNAL_SERVER_ERROR, err.to_string(), // or format!("{err:?}") + ) + .into_response(), + } + + //response }