网络请求打通,ws 打通
This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:networks_sdk/networks_sdk.dart';
|
||||
|
||||
import '../../../core/foundation/api_paths.dart';
|
||||
import '../../../domain/entities/user.dart';
|
||||
import 'package:im_app/core/foundation/api_paths.dart';
|
||||
import 'package:im_app/domain/entities/user.dart';
|
||||
|
||||
part 'login_request.g.dart';
|
||||
|
||||
/// # /auth/login — 登录接口
|
||||
/// # /app/api/auth/login-user — 使用 vcode_token 完成登录
|
||||
///
|
||||
/// 流程:发送验证码([SendOtpRequest])→ 校验验证码([VerifyOtpRequest])
|
||||
/// → ★ 用 vcode_token 登录(本请求)★ → 获得 access_token
|
||||
///
|
||||
/// ## 数据流位置
|
||||
///
|
||||
/// ```
|
||||
/// AuthRepositoryImpl.login(email, password)
|
||||
/// AuthRepositoryImpl.login(countryCode, contact, vcodeToken)
|
||||
/// → _client.executeRequest( ★ LoginRequest ★ ) ← 你在这里
|
||||
/// → 服务端 POST /auth/login
|
||||
/// → SDK 内部 ApiResponseWrapper 拆包 { code, message, data }
|
||||
/// → ★ LoginResponse ★ = data 字段,T in APIResponseWrapper<T> ← 也在这里
|
||||
/// → 服务端 POST /app/api/auth/login-user
|
||||
/// → SDK 拆包 {code, message, data} envelope
|
||||
/// → ★ LoginResponse ★ ← 也在这里
|
||||
/// → LoginResponse.toEntity() → User
|
||||
/// ```
|
||||
|
||||
@@ -100,24 +103,27 @@ class LoginResponse {
|
||||
@JsonKey(name: 'account_id')
|
||||
final String accountId;
|
||||
final LoginProfile profile;
|
||||
final String nonce;
|
||||
@JsonKey(name: 'access_token')
|
||||
final String accessToken;
|
||||
@JsonKey(name: 'refresh_token')
|
||||
final String refreshToken;
|
||||
@JsonKey(name: 'device_id')
|
||||
final String deviceId;
|
||||
final String nonce;
|
||||
@JsonKey(name: 'login_data')
|
||||
final String loginData;
|
||||
@JsonKey(name: 'is_verified')
|
||||
final bool? isVerified;
|
||||
|
||||
const LoginResponse({
|
||||
required this.accountId,
|
||||
required this.profile,
|
||||
required this.nonce,
|
||||
required this.accessToken,
|
||||
required this.refreshToken,
|
||||
required this.deviceId,
|
||||
required this.loginData,
|
||||
this.nonce = '',
|
||||
this.loginData = '',
|
||||
this.isVerified,
|
||||
});
|
||||
|
||||
User toEntity() => profile.toEntity();
|
||||
@@ -127,11 +133,10 @@ class LoginResponse {
|
||||
// Request
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
/// 登录请求
|
||||
/// 使用 vcode_token 完成登录的请求
|
||||
///
|
||||
/// `@ApiRequest` 一个注解搞定一切:
|
||||
/// - mixin 自动生成 path / method / requestType / includeToken / toJson
|
||||
/// - parameters getter 自动注册 `_$LoginResponseFromJson` 到 SDK 全局注册表
|
||||
/// 上游:[VerifyOtpRequest] 返回的 `token` 即 vcodeToken。
|
||||
/// 成功后 [LoginResponse.accessToken] 写入 ApiConfig,后续请求自动携带。
|
||||
@ApiRequest(
|
||||
path: ApiPaths.authLogin,
|
||||
method: HttpMethod.post,
|
||||
@@ -140,8 +145,15 @@ class LoginResponse {
|
||||
)
|
||||
class LoginRequest extends ApiRequestable<LoginResponse>
|
||||
with _$LoginRequestApi {
|
||||
final String email;
|
||||
final String password;
|
||||
@JsonKey(name: 'country_code')
|
||||
final String countryCode;
|
||||
final String contact;
|
||||
@JsonKey(name: 'vcode_token')
|
||||
final String vcodeToken;
|
||||
|
||||
LoginRequest({required this.email, required this.password});
|
||||
LoginRequest({
|
||||
required this.countryCode,
|
||||
required this.contact,
|
||||
required this.vcodeToken,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user