feat: add authenticated durable native Hope chat

This commit is contained in:
snowspeeder committed 2026-10-03 09:06:06 -04:00
1 parent 74d2b63614
commit 7dcd06c911
15 files changed
+1675 -9

No files matched your search

+10
View File
@@ -4,6 +4,11 @@ struct TokenResponse: Decodable, Equatable {
let token: String
let room: String
let user: User
let conversationID: String?
enum CodingKeys: String, CodingKey {
case token, room, user
case conversationID = "conversation_id"
}
struct User: Decodable, Equatable {
let id: String
@@ -44,6 +49,7 @@ final class TokenClient {
private let session: URLSession
var onUnauthorized: (() async -> Void)?
let bearerToken: String
var conversationID: String?
init(config: ServerConfig, bearerToken: String = "", session: URLSession? = nil) {
self.config = config
@@ -63,6 +69,10 @@ final class TokenClient {
guard !bearerToken.isEmpty else { throw AuthError.status(401) }
var request = URLRequest(url: config.baseURL.appendingPathComponent("token"))
request.httpMethod = "POST"
if let conversationID {
request.httpBody = try JSONSerialization.data(withJSONObject: ["conversation_id": conversationID])
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
}
request.setValue("Bearer \(bearerToken)", forHTTPHeaderField: "Authorization")
request.timeoutInterval = 10
let (data, response) = try await session.data(for: request)