Skip to content

Commit

Permalink
fix: login offline mode issues
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Dec 23, 2024
1 parent 2c6ff5a commit a03adcb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
19 changes: 7 additions & 12 deletions lib/features/auth/cubit/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ class AuthCubit extends Cubit<AuthState> {
}, (users) {
if (users.isEmpty) {
emit(AuthFirstAppLaunch());
return true;
return null;
} else if (users.length == 1) {
return fetchUserCredsFromCache(users.first).then((result) {
result.fold((error) {
emit(AuthErrorState(error));
return;
}, (creds) async {
// TODO: erick allow checking for connection result
final List<ConnectivityResult> connectivityResult =
await (Connectivity().checkConnectivity());

// Authenticate locally if no internet connection was found
// if (connectivityResult.contains(ConnectivityResult.none)) {
// emit(AuthenticatedState(user: users.first, localAuth: true));
// return;
// }
if (connectivityResult.contains(ConnectivityResult.none)) {
emit(AuthenticatedState(user: users.first, localAuth: true));
return;
}

authenticate(creds).then((auth) {
auth.fold((error) {
emit(AuthErrorState(error));
Expand All @@ -54,12 +55,6 @@ class AuthCubit extends Cubit<AuthState> {
);
}

StreamSubscription<List<ConnectivityResult>> subscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> result) {
// Received changes in available connectivity types!
});

/// Authenticate performs authentication mechanisms with both verisafe
/// and magnet to authenticate a user
Future<Either<String, bool>> authenticate(
Expand Down
21 changes: 1 addition & 20 deletions lib/features/auth/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@ class _LoginPageState extends State<LoginPage> {
bool validateForm() {
return _formState.currentState!.validate();
}
//
// /// Shows a dialog with [title] and [content]
// void _showMessageDialog(String title, String content) {
// showDialog(
// context: context,
// builder: (context) => AlertDialog(
// title: Text(title),
// content: Text(content),
// actions: [
// TextButton(
// onPressed: () {
// context.pop();
// },
// child: const Text("Ok"),
// ),
// ],
// ),
// );
// }

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -198,7 +179,7 @@ class _LoginPageState extends State<LoginPage> {
);
}, (r) {
HapticFeedback.heavyImpact();
GoRouter.of(context).pushNamed(
GoRouter.of(context).pushReplacementNamed(
AcademiaRouter.home,
);
});
Expand Down
1 change: 1 addition & 0 deletions lib/features/profile/views/profile_page_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _ProfilePageMobileState extends State<ProfilePageMobile> {
child: CustomScrollView(
slivers: [
SliverAppBar(
automaticallyImplyLeading: false,
actions: [
IconButton(
onPressed: () {},
Expand Down

0 comments on commit a03adcb

Please sign in to comment.