Files
ttstd_family_care/lib/features/auth/domain/auth_models.dart
TongTongStudio 8478a99eba feat(auth): 对接后端 open 模块认证接口并完善登录页
- 更新接口路径、字段和短信验证码场景,新增忘记密码/重置密码流程
- 增加 401 自动刷新 token 与统一错误处理
- 重构登录页 UI,支持退出确认、协议与法律文档入口
2026-08-17 09:30:25 +08:00

51 lines
1.4 KiB
Dart
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.
/// 认证领域实体。
///
/// 以不可变类表达,避免 UI / 仓库直接依赖后台 DTO 结构。
/// 因未运行 build_runner避免改动依赖与生成产物此处手写等价实现
/// 所有字段 final、提供 const 构造与 copyWith并手动实现 JSON 转换。
class LoginResult {
const LoginResult({
required this.token,
this.refreshToken,
this.userId,
this.phone,
});
final String token;
final String? refreshToken;
final String? userId;
final String? phone;
LoginResult copyWith({
String? token,
String? refreshToken,
String? userId,
String? phone,
}) {
return LoginResult(
token: token ?? this.token,
refreshToken: refreshToken ?? this.refreshToken,
userId: userId ?? this.userId,
phone: phone ?? this.phone,
);
}
factory LoginResult.fromJson(Map<String, dynamic> json) {
// 后端 C 端open 模块)返回 AuthenticationToken{ tokenType, accessToken, refreshToken, expiresIn }。
// 兼容旧字段 token部分场景/历史返回),优先读取 accessToken。
return LoginResult(
token: (json['accessToken'] ?? json['token']) as String,
refreshToken: json['refreshToken'] as String?,
userId: json['userId'] as String?,
phone: json['phone'] as String?,
);
}
}
/// 发送短信验证码的用途。
enum SmsScene {
login,
register,
resetPassword,
}