feat: 定义仓库协议与用例(含会话)
This commit is contained in:
28
IosClientKit/Sources/CoreDomain/SessionRepository.swift
Normal file
28
IosClientKit/Sources/CoreDomain/SessionRepository.swift
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user