feat : auth package

This commit is contained in:
2025-05-11 11:49:51 +03:30
parent 8cc4a7517c
commit 9ec761e6eb
34 changed files with 665 additions and 475 deletions

View File

@@ -1,12 +0,0 @@
import 'package:hive_ce_flutter/hive_flutter.dart';
import 'package:rasadyar_app/data/data_provider/local_storage/i_local_storage_provider.dart';
enum HiveBoxNames { user, settings, auth }
class HiveProvider extends ILocalStorageProvider {
@override
Future<void> init() async {
await Hive.initFlutter();
}
}

View File

@@ -1 +0,0 @@
const int userTypeId = 0;

View File

@@ -1,3 +0,0 @@
abstract class ILocalStorageProvider {
Future<void> init();
}

View File

@@ -1,19 +0,0 @@
import 'package:hive_ce_flutter/hive_flutter.dart';
import 'package:rasadyar_app/data/data_provider/local_storage/hive/hive_provider.dart';
abstract class IUserLocalStorage {
Future<bool> userAuthed();
}
class UserLocalStorage extends IUserLocalStorage {
final user = Hive.box(HiveBoxNames.user.name);
@override
Future<bool> userAuthed() async {
if (user.isNotEmpty ) {
return true;
} else {
return false;
}
}
}

View File

@@ -1,17 +0,0 @@
import 'package:hive_ce/hive.dart';
import '../../data_provider/local_storage/hive/hive_types.dart';
part 'user_model.g.dart';
@HiveType(typeId: userTypeId)
class UserModel extends HiveObject{
@HiveField(0)
String? token;
@HiveField(1)
String? refreshToken;
UserModel({this.token, this.refreshToken});
}

View File

@@ -1,17 +0,0 @@
import 'package:rasadyar_app/data/data_source/local_storage/user/user_local_storage.dart';
abstract class IUserRepository {
Future<bool> userAuthed();
}
class UserRepository implements IUserRepository {
final IUserLocalStorage _userLocalStorage;
UserRepository(this._userLocalStorage);
@override
Future<bool> userAuthed() async {
return await _userLocalStorage.userAuthed();
}
}

View File

@@ -1,17 +0,0 @@
import 'package:get/get.dart';
import 'package:rasadyar_app/domain/repository/user/user_repository.dart';
import 'package:rasadyar_app/infrastructure/di/di.dart';
class UserService extends GetxService {
late IUserRepository _userLocalStorage;
@override
void onInit() {
return super.onInit();
// _userLocalStorage = di.get<UserRepository>();
}
Future<bool> isUserAuthed() async {
return await _userLocalStorage.userAuthed();
}
}

View File

@@ -1,15 +1,10 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_app/domain/service/user/user_service.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/infrastructure/di/di.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
setupInjection();
await setupAllProvider();
runApp(MyApp());
// runApp(DevicePreview(builder: (context) => ForDevicePreview(),));
}
@@ -46,7 +41,7 @@ class MyApp extends StatelessWidget {
colorScheme: ColorScheme.fromSeed(seedColor: AppColor.blueNormal),
),
initialRoute: AppPages.initRoutes,
initialBinding: BindingsBuilder.put(() => UserService()),
// initialBinding: BindingsBuilder.put(() => UserService()),
getPages: AppPages.pages,
locale: const Locale("fa", "IR"),
supportedLocales: const [