@@ -72,45 +72,38 @@ type PathParams = Path<SessionQuery>;
7272#[ debug_handler]
7373pub ( crate ) async fn delete (
7474 Path ( session_query) : PathParams ,
75- token : Option < AuthToken > ,
75+ AuthToken ( token) : AuthToken ,
7676) -> impl Response < DeleteResponse > {
77- #[ expect(
78- unused_assignments,
79- reason = "This will fix itself once the TODO is resolved"
80- ) ]
81- let mut response_header = None ;
82-
83- match session_query {
84- SessionQuery :: Current => {
85- let Some ( AuthToken ( token) ) = token else {
86- return Err ( api:: Error :: ResourceNotFound ) ;
87- } ;
77+ let token_hash = hash_without_salt ( & token) ;
8878
89- let token_hash = hash_without_salt ( & token) ;
79+ let response_header = match session_query {
80+ // The user requested deletion of a session other than their current one.
81+ SessionQuery :: Id ( id) if id. as_ref ( ) != token_hash. as_ref ( ) => {
82+ // TODO: Implement signing out specific sessions in the account settings.
83+ return Err ( api:: Error :: AccessDenied ) ;
84+ }
9085
86+ // The user requested deletion of their current session.
87+ _ => {
9188 let sessions_deleted = db:: transaction!( async |tx| -> TxResult <_, api:: Error > {
9289 Ok ( sqlx:: query!(
9390 "DELETE FROM sessions
9491 WHERE token_hash = $1" ,
9592 token_hash. as_ref( ) ,
9693 )
9794 . execute( tx. as_mut( ) )
98- . await ?)
95+ . await ?
96+ . rows_affected( ) )
9997 } )
100- . await ?
101- . rows_affected ( ) ;
98+ . await ?;
10299
103100 if sessions_deleted == 0 {
104101 return Err ( api:: Error :: ResourceNotFound ) ;
105102 }
106103
107- response_header = Some ( SessionCookie :: expired ( ) . to_header ( ) ) ;
104+ Some ( SessionCookie :: expired ( ) . to_header ( ) )
108105 }
109- SessionQuery :: Id ( _) => {
110- // TODO: Implement signing out specific sessions in the account settings.
111- return Err ( api:: Error :: AccessDenied ) ;
112- }
113- }
106+ } ;
114107
115108 Ok ( (
116109 StatusCode :: OK ,
0 commit comments