Files
tripz-llc/apps/rider/lib/features/auth/data/auth_repository.dart
T
HamzaandClaude Opus 4.8 6116d23d0c flutter(rider): rebuild lib on Cubit/Bloc + Tripz backend (core + auth slice)
- keep store identity (com.mobileapp.store.ride, shorebird, firebase, fonts); old lib -> lib_old_getx
- core: config/di/router(go_router)/theme/api_client(dio+tenant+bearer)/token_store(secure)
- auth: repo + AuthCubit + OTP phone/otp screens; home: flutter_map (OSM placeholder, انطلق TODO)
- android usesCleartextTraffic=true for http API; maps=flutter_map (no Google), state=Cubit

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 20:47:55 +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'] ?? 'rider') 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();
}