MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / delete_session

Function delete_session

nodedb/src/control/server/http/routes/auth_session.rs:65–87  ·  view source on GitHub ↗

`DELETE /v1/auth/session` — Invalidate a session handle. ```text DELETE /v1/auth/session Authorization: Bearer X-Session-Id: nds_... ``` The caller must present a valid bearer token. A session handle may only be invalidated by the authenticated caller — the identity is verified before any session state is read or mutated.

(
    ConnectInfo(peer): ConnectInfo<SocketAddr>,
    headers: HeaderMap,
    State(state): State<AppState>,
)

Source from the content-addressed store, hash-verified

63/// invalidated by the authenticated caller — the identity is verified before
64/// any session state is read or mutated.
65pub async fn delete_session(
66 ConnectInfo(peer): ConnectInfo<SocketAddr>,
67 headers: HeaderMap,
68 State(state): State<AppState>,
69) -> Result<impl IntoResponse, ApiError> {
70 // Auth check must come first — return 401/403 before touching session state.
71 let _identity = {
72 let peer_str = peer.to_string();
73 crate::control::server::http::auth::resolve_identity(&headers, &state, &peer_str)?
74 };
75
76 let handle = headers
77 .get("x-session-id")
78 .and_then(|v| v.to_str().ok())
79 .ok_or_else(|| ApiError::BadRequest("missing X-Session-Id header".into()))?;
80
81 let found = state.shared.session_handles.invalidate(handle);
82 if !found {
83 return Err(ApiError::BadRequest("session handle not found".into()));
84 }
85
86 Ok(axum::Json(HttpStatusOk::ok()))
87}

Callers

nothing calls this directly

Calls 6

resolve_identityFunction · 0.85
to_stringMethod · 0.80
okFunction · 0.50
getMethod · 0.45
okMethod · 0.45
invalidateMethod · 0.45

Tested by

no test coverage detected