Files
tripz-llc/apps/driver-archive-cubit/lib/features/auth/data/auth_repository.dart
T
Hamza-AyedandClaude Opus 5 9909d9b4c1 chore: أرشفة تطبيقات ولوحات تريبز التي سيحلّ محلها كود سيرو
استكمال قرار 2026-07-27 (كوميت fff76c9 أرشف الباك إند):
  apps/rider          → apps/rider-archive-cubit
  apps/driver         → apps/driver-archive-cubit
  dashboards/admin-web    → dashboards/admin-web-archive
  dashboards/service-web  → dashboards/service-web-archive

إعادة تسمية بلا تعديل محتوى. rider/driver كانا إعادة بناء Cubit مبنية على
عقد NestJS المؤرشف. admin-web و service-web نموذجان بملف HTML واحد (164 و
128 سطراً) — يحلّ محلهما siro_admin و siro_service المكتملان.

يُحمل من المؤرشف ولا يُعاد اكتشافه: عقد map-saas المثبَّت بالتجربة في
apps/rider-archive-cubit/lib/core/api/ (x-api-key ترويسة، reverse مصفوفة،
route في points) ودرس مسار FCM.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:12:04 +03:00

54 lines
1.4 KiB
Dart

import 'package:dio/dio.dart';
import '../../../core/api/api_client.dart';
import '../../../core/storage/token_store.dart';
class AppUser {
final String id;
final String phone;
final String? name;
final String role;
AppUser({required this.id, required this.phone, this.name, required this.role});
factory AppUser.fromJson(Map<String, dynamic> j) => AppUser(
id: j['id'] as String,
phone: (j['phone'] ?? '') as String,
name: j['name'] as String?,
role: (j['role'] ?? 'driver') as String,
);
}
class AuthRepository {
final ApiClient _api;
final TokenStore _store;
AuthRepository(this._api, this._store);
Future<void> sendOtp(String phone) async {
await _api.dio.post('/auth/send-otp', data: {'phone': phone});
}
Future<AppUser> verify(String phone, String code) async {
final r = await _api.dio.post(
'/auth/verify-otp',
data: {'phone': phone, 'code': code},
);
await _store.save(
r.data['access_token'] as String,
r.data['refresh_token'] as String,
);
return AppUser.fromJson(Map<String, dynamic>.from(r.data['user'] as Map));
}
Future<AppUser?> me() async {
try {
final r = await _api.dio.get('/users/me');
return AppUser.fromJson(Map<String, dynamic>.from(r.data as Map));
} on DioException {
return null;
}
}
Future<void> logout() => _store.clear();
}