feat: profile and subs

This commit is contained in:
2026-06-17 11:32:18 +03:30
parent 943ba13872
commit e9f294fa19
19 changed files with 1762 additions and 34 deletions
+23 -4
View File
@@ -9,23 +9,30 @@ enum AuthStatus { initial, loading, otpSent, authenticated, error }
class AuthState extends Equatable {
final AuthStatus status;
final String mobile;
final bool needsProfile; // پس از ورود، آیا کاربر باید نام/آواتار انتخاب کند
final String? error;
const AuthState({
this.status = AuthStatus.initial,
this.mobile = '',
this.needsProfile = false,
this.error,
});
AuthState copyWith({AuthStatus? status, String? mobile, String? error}) =>
AuthState copyWith(
{AuthStatus? status,
String? mobile,
bool? needsProfile,
String? error}) =>
AuthState(
status: status ?? this.status,
mobile: mobile ?? this.mobile,
needsProfile: needsProfile ?? this.needsProfile,
error: error,
);
@override
List<Object?> get props => [status, mobile, error];
List<Object?> get props => [status, mobile, needsProfile, error];
}
class AuthCubit extends Cubit<AuthState> {
@@ -45,13 +52,25 @@ class AuthCubit extends Cubit<AuthState> {
Future<void> verifyOtp(String code) async {
emit(state.copyWith(status: AuthStatus.loading));
try {
await _repo.verifyOtp(state.mobile, code);
emit(state.copyWith(status: AuthStatus.authenticated));
final hasName = await _repo.verifyOtp(state.mobile, code);
emit(state.copyWith(
status: AuthStatus.authenticated, needsProfile: !hasName));
} catch (e) {
emit(state.copyWith(status: AuthStatus.error, error: _msg(e)));
}
}
/// ذخیره‌ی نام و آواتار؛ سپس نیازی به صفحه‌ی پروفایل نیست.
Future<bool> saveProfile(String name, String avatar) async {
try {
await _repo.updateProfile(name, avatar);
emit(state.copyWith(needsProfile: false));
return true;
} catch (_) {
return false;
}
}
Future<void> logout() async {
await _repo.logout();
emit(const AuthState());