feat: 定义仓库协议与用例(含会话)

This commit is contained in:
AndyChen1024
2026-09-15 14:35:52 +08:00
parent 14eb5ad44d
commit ec1eed8f04
10 changed files with 139 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
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
}