feat: implement splash and onboarding flows, update app assets, and add project design documentation
This commit is contained in:
@@ -8,13 +8,34 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
AuthCubit(this._repo) : super(const AuthState());
|
||||
|
||||
Future<void> checkAuth() async {
|
||||
final hasToken = await _repo.hasSavedToken();
|
||||
if (hasToken) {
|
||||
final cachedUser = await _repo.getCachedUser();
|
||||
if (cachedUser != null) {
|
||||
emit(state.copyWith(
|
||||
status: AuthStatus.authenticated,
|
||||
user: cachedUser,
|
||||
));
|
||||
}
|
||||
}
|
||||
final user = await _repo.me();
|
||||
emit(state.copyWith(
|
||||
status: user != null ? AuthStatus.authenticated : AuthStatus.unauthenticated,
|
||||
user: user,
|
||||
));
|
||||
if (user != null) {
|
||||
emit(state.copyWith(
|
||||
status: AuthStatus.authenticated,
|
||||
user: user,
|
||||
));
|
||||
} else {
|
||||
final hasTokenAfterMe = await _repo.hasSavedToken();
|
||||
if (!hasTokenAfterMe) {
|
||||
emit(state.copyWith(
|
||||
status: AuthStatus.unauthenticated,
|
||||
user: null,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> sendOtp(String phone) async {
|
||||
if (phone.trim().isEmpty) {
|
||||
emit(state.copyWith(status: AuthStatus.error, error: 'أدخل رقم الهاتف'));
|
||||
@@ -43,4 +64,14 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
await _repo.logout();
|
||||
emit(const AuthState(status: AuthStatus.unauthenticated));
|
||||
}
|
||||
|
||||
Future<void> updateName(String name) async {
|
||||
try {
|
||||
emit(state.copyWith(status: AuthStatus.authenticating));
|
||||
final user = await _repo.updateName(name);
|
||||
emit(state.copyWith(status: AuthStatus.authenticated, user: user));
|
||||
} catch (_) {
|
||||
emit(state.copyWith(status: AuthStatus.error, error: 'تعذّر حفظ الاسم'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user