lougout all device fix
This commit is contained in:
BIN
db/1.sqlite-shm
BIN
db/1.sqlite-shm
Binary file not shown.
Binary file not shown.
@@ -781,12 +781,12 @@ pub async fn logout_from_all_devices (
|
||||
State(state): State<AppState>,
|
||||
Extension(keys): Extension<JwtKeys>,
|
||||
AuthClaims { user_id, hotel_id }: AuthClaims,
|
||||
Json(payload): Json<LoginRefreshTokenValues>
|
||||
//Json(payload): Json<LoginRefreshTokenValues>
|
||||
) -> 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
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user