fix : auth middleware
This commit is contained in:
@@ -3,3 +3,6 @@
|
||||
/// More dartdocs go here.
|
||||
library;
|
||||
|
||||
export 'data/services/auth_middelware.dart';
|
||||
export 'data/services/auth_service.dart';
|
||||
export 'data/di/auth_di.dart';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:auths/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import '../di/auth_di.dart';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:auths/data/common/constant.dart';
|
||||
import 'package:auths/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:auths/data/services/auth_service.dart';
|
||||
import 'package:rasadyar_auth/data/common/constant.dart';
|
||||
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_auth/data/services/auth_service.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import '../common/dio_manager.dart';
|
||||
@@ -17,7 +18,8 @@ Future<void> setupAuthDI() async {
|
||||
() => AuthRepositoryImpl(dioRemote),
|
||||
);
|
||||
diAuth.registerLazySingleton(() => AuthService());
|
||||
|
||||
diAuth.registerLazySingleton(() => TokenStorageService());
|
||||
|
||||
//hive
|
||||
//await diAuth.registerCachedFactoryAsync(() async=>await ,)
|
||||
//await diAuth.registerCachedFactoryAsync(() async=>await ,)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_auth/data/di/auth_di.dart';
|
||||
import 'package:rasadyar_auth/data/services/token_storage_service.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import '../../presentation/routes/pages.dart';
|
||||
|
||||
class AuthMiddleware extends GetMiddleware{
|
||||
class AuthMiddleware extends GetMiddleware {
|
||||
var tokenService = diAuth.get<TokenStorageService>();
|
||||
|
||||
@override
|
||||
RouteSettings? redirect(String? route) {
|
||||
if(route == AuthPaths.auth) {
|
||||
return const RouteSettings(name: AuthPaths.moduleList);
|
||||
eLog('redirect');
|
||||
final refreshToken = tokenService.getRefreshToken();
|
||||
final accessToken = tokenService.getAccessToken();
|
||||
|
||||
if (refreshToken == null || accessToken == null) {
|
||||
return RouteSettings(name: AuthPaths.moduleList);
|
||||
}
|
||||
return super.redirect(route);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -43,11 +43,10 @@ class TokenStorageService extends GetxService {
|
||||
value: token,
|
||||
);
|
||||
|
||||
Future<String?> getAccessToken() async =>
|
||||
await _localStorage.read(boxName: _boxName, key: _accessTokenKey);
|
||||
|
||||
Future<String?> getRefreshToken() async =>
|
||||
await _localStorage.read(boxName: _boxName, key: _refreshTokenKey);
|
||||
String? getAccessToken() =>
|
||||
_localStorage.read<String?>(boxName: _boxName, key: _accessTokenKey);
|
||||
String? getRefreshToken() =>
|
||||
_localStorage.read<String?>(boxName: _boxName, key: _refreshTokenKey);
|
||||
|
||||
Future<void> deleteTokens() async => await _localStorage.clear(_boxName);
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// Do not modify
|
||||
// Check in to version control
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:auths/data/models/local/user_local/user_local_model.dart';
|
||||
import 'package:rasadyar_auth/data/models/local/user_local/user_local_model.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
extension HiveRegistrar on HiveInterface {
|
||||
void registerAdapters() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: auths
|
||||
name: rasadyar_auth
|
||||
description: "A new Flutter project."
|
||||
version: 0.0.1
|
||||
publish_to: 'none'
|
||||
|
||||
@@ -13,6 +13,7 @@ export 'package:geolocator/geolocator.dart';
|
||||
export 'package:get/get.dart';
|
||||
//di
|
||||
export 'package:get_it/get_it.dart';
|
||||
export 'injection/di.dart';
|
||||
|
||||
//local storage
|
||||
export 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'i_local_storage.dart';
|
||||
|
||||
@@ -33,36 +33,42 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<T?> read<T>({required String boxName,required String key}) async {
|
||||
Box? box = await getBox(boxName);
|
||||
return box.get(key) as T?;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Future<void> add({required String boxName,required dynamic value}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addAll({required String boxName,required Iterable values}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.addAll(values);
|
||||
}
|
||||
|
||||
Future<Box<T>> getBox<T>(String boxName) async {
|
||||
final box = _boxes[boxName];
|
||||
if (box is Box<T>) {
|
||||
return box;
|
||||
} else {
|
||||
throw Exception('Box $boxName is not of expected type $T');
|
||||
T? read<T>({required String boxName, required String key}) {
|
||||
try {
|
||||
Box? box = getBox(boxName);
|
||||
return box?.get(key) as T?;
|
||||
} on Exception catch (e) {
|
||||
eLog(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(String boxName) async{
|
||||
Future<void> add({required String boxName, required dynamic value}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addAll({
|
||||
required String boxName,
|
||||
required Iterable values,
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.addAll(values);
|
||||
}
|
||||
|
||||
Box<T>? getBox<T>(String boxName) {
|
||||
final box = _boxes[boxName];
|
||||
if (box is Box<T>) {
|
||||
return box;
|
||||
} else {
|
||||
throw Exception('Box $boxName is not of exist');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear(String boxName) async {
|
||||
await _boxes[boxName]?.clear();
|
||||
}
|
||||
|
||||
@@ -74,8 +80,8 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required String key,
|
||||
}) async {
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.delete(key);
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.delete(key);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -83,15 +89,15 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required String key,
|
||||
required value,
|
||||
}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.put(key, value);
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.put(key, value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveAll({required String boxName, required Map entries}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.putAll(entries);
|
||||
Future<void> saveAll({required String boxName, required Map entries}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.putAll(entries);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -99,8 +105,8 @@ class HiveLocalStorage implements ILocalStorage {
|
||||
required String boxName,
|
||||
required int index,
|
||||
required value,
|
||||
}) async{
|
||||
Box<dynamic>? box = await getBox(boxName);
|
||||
await box.putAt(index, value);
|
||||
}) async {
|
||||
Box<dynamic>? box = getBox(boxName);
|
||||
await box?.putAt(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ abstract class ILocalStorage<E> {
|
||||
String? collection,
|
||||
});
|
||||
|
||||
Future<T?> read<T>({required String boxName, required String key});
|
||||
T? read<T>({required String boxName, required String key});
|
||||
|
||||
Future<void> deleteValue({required String boxName, required String key});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ final diCore = GetIt.instance;
|
||||
Future<void> setupAllProvider() async {
|
||||
await _setUpLogger();
|
||||
await _setupLocalStorage();
|
||||
await _setupRemote();
|
||||
await diCore.allReady();
|
||||
}
|
||||
|
||||
@@ -21,5 +22,5 @@ Future<void> _setupLocalStorage() async {
|
||||
|
||||
|
||||
Future<void> _setupRemote() async {
|
||||
diCore.registerSingleton<HiveLocalStorage>(HiveLocalStorage());
|
||||
// diCore.registerSingleton<HiveLocalStorage>(HiveLocalStorage());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/buttons/fab.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
class AddSupervisionLogic extends GetxController {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/inspection.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/data/utils/marker_generator.dart';
|
||||
import 'package:inspection/presentation/filter/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/data/utils/marker_generator.dart';
|
||||
import 'package:rasadyar_inspection/presentation/filter/view.dart';
|
||||
|
||||
class InspectorFilterLogic extends GetxController
|
||||
with GetTickerProviderStateMixin {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/buttons/fab.dart';
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/presentation/registration_of_violation/logic.dart';
|
||||
import 'package:inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/buttons/fab.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
class RegistrationOfViolationPage
|
||||
extends GetView<RegistrationOfViolationLogic> {
|
||||
const RegistrationOfViolationPage({super.key});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:inspection/presentation/action/view.dart';
|
||||
import 'package:inspection/presentation/filter/view.dart';
|
||||
import 'package:inspection/presentation/profile/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/presentation/action/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/filter/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/profile/view.dart';
|
||||
|
||||
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import 'package:rasadyar_auth/auth.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:inspection/presentation/action/logic.dart';
|
||||
import 'package:inspection/presentation/add_mobile_inspector/logic.dart';
|
||||
import 'package:inspection/presentation/add_mobile_inspector/view.dart';
|
||||
import 'package:inspection/presentation/add_supervision/logic.dart';
|
||||
import 'package:inspection/presentation/add_supervision/view.dart';
|
||||
import 'package:inspection/presentation/display_information/logic.dart';
|
||||
import 'package:inspection/presentation/display_information/view.dart';
|
||||
import 'package:inspection/presentation/filter/logic.dart';
|
||||
import 'package:inspection/presentation/location_details/logic.dart';
|
||||
import 'package:inspection/presentation/location_details/view.dart';
|
||||
import 'package:inspection/presentation/profile/logic.dart';
|
||||
import 'package:inspection/presentation/profile/view.dart';
|
||||
import 'package:inspection/presentation/registration_of_violation/logic.dart';
|
||||
import 'package:inspection/presentation/registration_of_violation/view.dart';
|
||||
import 'package:inspection/presentation/root/logic.dart';
|
||||
import 'package:inspection/presentation/root/view.dart';
|
||||
import 'package:inspection/presentation/routes/app_routes.dart';
|
||||
import 'package:rasadyar_inspection/presentation/action/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/add_mobile_inspector/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/add_mobile_inspector/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/add_supervision/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/add_supervision/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/display_information/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/display_information/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/filter/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/location_details/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/location_details/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/profile/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/profile/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/registration_of_violation/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/registration_of_violation/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/root/logic.dart';
|
||||
import 'package:rasadyar_inspection/presentation/root/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/routes/app_routes.dart';
|
||||
|
||||
sealed class InspectionPages {
|
||||
InspectionPages._();
|
||||
@@ -24,6 +25,7 @@ sealed class InspectionPages {
|
||||
GetPage(
|
||||
name: InspectionRoutes.inspection,
|
||||
page: () => RootPage(),
|
||||
middlewares: [AuthMiddleware()],
|
||||
binding: BindingsBuilder(() {
|
||||
Get.put(RootLogic());
|
||||
Get.put(InspectorFilterLogic());
|
||||
|
||||
@@ -600,6 +600,13 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
rasadyar_auth:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../auth"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
rasadyar_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: inspection
|
||||
name: rasadyar_inspection
|
||||
description: "inspection module for rasadyar"
|
||||
publish_to: 'none'
|
||||
version: 1.0.1
|
||||
@@ -10,4 +10,6 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
rasadyar_core:
|
||||
path: ../core
|
||||
path: ../core
|
||||
rasadyar_auth:
|
||||
path: ../auth
|
||||
Reference in New Issue
Block a user