change position to revoke all session

This commit is contained in:
cheykrym 2025-10-24 10:29:20 +03:00
parent be6394f6fb
commit 020aa8de5d
3 changed files with 53 additions and 5 deletions

View File

@ -128,6 +128,49 @@ final class SessionsService {
} }
} }
func revoke(sessionId: UUID, completion: @escaping (Result<String, Error>) -> Void) {
client.request(
path: "/v1/auth/sessions/revoke/\(sessionId.uuidString)",
method: .post,
requiresAuth: true
) { [decoder] result in
switch result {
case .success(let response):
do {
let apiResponse = try decoder.decode(APIResponse<MessagePayload>.self, from: response.data)
guard apiResponse.status == "fine" else {
let message = apiResponse.detail ?? NSLocalizedString("Не удалось завершить сессию.", comment: "Sessions service revoke unexpected status")
completion(.failure(SessionsServiceError.unexpectedStatus(message)))
return
}
completion(.success(apiResponse.data.message))
} catch {
let debugMessage = Self.describeDecodingError(error: error, data: response.data)
if AppConfig.DEBUG {
print("[SessionsService] decode revoke failed: \(debugMessage)")
}
completion(.failure(SessionsServiceError.decoding(debugDescription: debugMessage)))
}
case .failure(let error):
if case let NetworkError.server(_, data) = error,
let data,
let message = Self.errorMessage(from: data) {
completion(.failure(SessionsServiceError.unexpectedStatus(message)))
return
}
completion(.failure(error))
}
}
}
func revoke(sessionId: UUID) async throws -> String {
try await withCheckedThrowingContinuation { continuation in
revoke(sessionId: sessionId) { result in
continuation.resume(with: result)
}
}
}
private static func decodeDate(from decoder: Decoder) throws -> Date { private static func decodeDate(from decoder: Decoder) throws -> Date {
let container = try decoder.singleValueContainer() let container = try decoder.singleValueContainer()
let string = try container.decode(String.self) let string = try container.decode(String.self)

View File

@ -987,6 +987,9 @@
"Не удалось завершить другие сессии." : { "Не удалось завершить другие сессии." : {
"comment" : "Sessions service revoke-all unexpected status" "comment" : "Sessions service revoke-all unexpected status"
}, },
"Не удалось завершить сессию." : {
"comment" : "Sessions service revoke unexpected status"
},
"Не удалось загрузить историю чата." : { "Не удалось загрузить историю чата." : {
}, },

View File

@ -50,17 +50,19 @@ struct ActiveSessionsView: View {
.padding(.vertical, 8) .padding(.vertical, 8)
} }
} }
if !otherSessions.isEmpty{
Section {
revokeOtherSessionsButton
}
}
if !otherSessions.isEmpty { if !otherSessions.isEmpty {
Section(header: Text(String(format: NSLocalizedString("Другие устройства (%d)", comment: "Заголовок секции других устройств с количеством"), otherSessions.count))) { Section(header: Text(String(format: NSLocalizedString("Другие устройства (%d)", comment: "Заголовок секции других устройств с количеством"), otherSessions.count))) {
ForEach(otherSessions) { session in ForEach(otherSessions) { session in
sessionRow(for: session) sessionRow(for: session)
} }
} }
Section {
revokeOtherSessionsButton
}
} }
} }
} }