fix(ios): send affine version on sign in (#11058)

This commit is contained in:
EYHN
2025-03-21 12:35:34 +08:00
committed by GitHub
parent 55a60906a5
commit bdd547d8db
6 changed files with 44 additions and 6 deletions
@@ -0,0 +1,20 @@
import Foundation
final class AppConfigManager {
struct AppConfig: Decodable {
let affineVersion: String
}
static var affineVersion: String? = nil
static func getAffineVersion() -> String {
if affineVersion == nil {
let file = Bundle(for: AppConfigManager.self).url(forResource: "capacitor.config", withExtension: "json")!
let data = try! Data(contentsOf: file)
let config = try! JSONDecoder().decode(AppConfig.self, from: data)
affineVersion = config.affineVersion
}
return affineVersion!
}
}
@@ -82,7 +82,7 @@ public class AuthPlugin: CAPPlugin, CAPBridgedPlugin {
let (data, response) = try await self.fetch(endpoint, method: "POST", action: "/api/auth/sign-in", headers: [
"x-captcha-token": verifyToken,
"x-captcha-challenge": challenge,
"x-captcha-challenge": challenge
], body: ["email": email, "password": password])
if response.statusCode >= 400 {
@@ -157,6 +157,7 @@ public class AuthPlugin: CAPPlugin, CAPBridgedPlugin {
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONEncoder().encode(body!)
}
request.setValue(AppConfigManager.getAffineVersion(), forHTTPHeaderField: "x-affine-version")
request.timeoutInterval = 10 // time out 10s
let (data, response) = try await URLSession.shared.data(for: request);