استكمال قرار 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>
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import '../data/auth_repository.dart';
|
|
import 'auth_state.dart';
|
|
|
|
class AuthCubit extends Cubit<AuthState> {
|
|
final AuthRepository _repo;
|
|
|
|
AuthCubit(this._repo) : super(const AuthState());
|
|
|
|
Future<void> checkAuth() async {
|
|
final user = await _repo.me();
|
|
emit(state.copyWith(
|
|
status: user != null ? AuthStatus.authenticated : AuthStatus.unauthenticated,
|
|
user: user,
|
|
));
|
|
}
|
|
|
|
Future<void> sendOtp(String phone) async {
|
|
if (phone.trim().isEmpty) {
|
|
emit(state.copyWith(status: AuthStatus.error, error: 'أدخل رقم الهاتف'));
|
|
return;
|
|
}
|
|
try {
|
|
emit(state.copyWith(status: AuthStatus.authenticating, phone: phone.trim()));
|
|
await _repo.sendOtp(phone.trim());
|
|
emit(state.copyWith(status: AuthStatus.codeSent, phone: phone.trim()));
|
|
} catch (_) {
|
|
emit(state.copyWith(status: AuthStatus.error, error: 'تعذّر إرسال الرمز'));
|
|
}
|
|
}
|
|
|
|
Future<void> verify(String code) async {
|
|
try {
|
|
emit(state.copyWith(status: AuthStatus.authenticating));
|
|
final user = await _repo.verify(state.phone, code.trim());
|
|
emit(state.copyWith(status: AuthStatus.authenticated, user: user));
|
|
} catch (_) {
|
|
emit(state.copyWith(status: AuthStatus.error, error: 'رمز غير صحيح'));
|
|
}
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
await _repo.logout();
|
|
emit(const AuthState(status: AuthStatus.unauthenticated));
|
|
}
|
|
}
|