feat : auth package
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
const int userTypeId = 0;
|
||||
@@ -1,3 +0,0 @@
|
||||
abstract class ILocalStorageProvider {
|
||||
Future<void> init();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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});
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 [
|
||||
|
||||
Reference in New Issue
Block a user