Files
patbond-flutter/lib/features/auth/auth_models.dart
T
lixi 845e92fa7d fix: UserProfile.phone 改为可空,消除非空强转崩溃点
- 跨端契约核对发现(功能清单「跨端核对发现」项):服务端 phone 可返回 null
- 门禁:format 0 changed / analyze 0 issues / flutter test 30 passed
2026-09-04 14:55:40 +08:00

59 lines
1.6 KiB
Dart

/// 认证接口的响应模型(接口契约冻结稿,字段名与后端一致)。
class AuthTokens {
const AuthTokens({
required this.userId,
required this.tokenType,
required this.accessToken,
required this.accessTokenExpiresAt,
required this.refreshToken,
required this.refreshTokenExpiresAt,
});
factory AuthTokens.fromJson(Map<String, dynamic> json) {
return AuthTokens(
userId: json['userId'] as String,
tokenType: json['tokenType'] as String,
accessToken: json['accessToken'] as String,
accessTokenExpiresAt: DateTime.parse(
json['accessTokenExpiresAt'] as String,
),
refreshToken: json['refreshToken'] as String,
refreshTokenExpiresAt: DateTime.parse(
json['refreshTokenExpiresAt'] as String,
),
);
}
final String userId;
final String tokenType;
final String accessToken;
final DateTime accessTokenExpiresAt;
final String refreshToken;
final DateTime refreshTokenExpiresAt;
}
/// `GET /api/v1/me` 的用户资料。
class UserProfile {
const UserProfile({
required this.userId,
required this.username,
required this.phone,
required this.createdAt,
});
factory UserProfile.fromJson(Map<String, dynamic> json) {
return UserProfile(
userId: json['userId'] as String,
username: json['username'] as String,
// 服务端可返回 null(历史数据或未来第三方注册),不得非空强转。
phone: json['phone'] as String?,
createdAt: DateTime.parse(json['createdAt'] as String),
);
}
final String userId;
final String username;
final String? phone;
final DateTime createdAt;
}