Files
ios-client/IosClientKit/Sources/CoreDomain/SessionRepository.swift
2026-09-15 14:35:52 +08:00

29 lines
880 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// 会话相关错误。
public enum SessionError: Error, Sendable, LocalizedError {
case invalidPhone
case wrongCode
case phoneNotMatched
public var errorDescription: String? {
switch self {
case .invalidPhone: return "请输入正确的手机号"
case .wrongCode: return "验证码错误"
case .phoneNotMatched: return "手机号未匹配,无法登录"
}
}
}
/// 会话仓库协议(登录态 / 手机号登录)。
public protocol SessionRepository: Sendable {
/// 观察登录态。
func observeIsLoggedIn() -> AsyncThrowingStream<Bool, Error>
/// 请求短信验证码。
func requestSmsCode(phone: String) async throws
/// 手机号 + 验证码登录。
func login(phone: String, code: String) async throws
/// 退出登录。
func logout() async throws
}