diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index 65fd7370b..792084d73 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -5,6 +5,7 @@ import 'dart:convert'; import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; +import 'package:flutter/foundation.dart'; // Project imports: import 'package:invoiceninja_flutter/.env.dart'; @@ -579,11 +580,9 @@ abstract class CompanyEntity extends Object ); bool isModuleEnabled(EntityType entityType) { - /* - if (entityType == EntityType.purchaseOrder) { + if (kReleaseMode && entityType == EntityType.purchaseOrder) { return false; } - */ if ((entityType == EntityType.invoice || entityType == EntityType.payment) && diff --git a/lib/ui/auth/login_vm.dart b/lib/ui/auth/login_vm.dart index ae3ebb816..3dc573728 100644 --- a/lib/ui/auth/login_vm.dart +++ b/lib/ui/auth/login_vm.dart @@ -225,9 +225,8 @@ class LoginVM { try { WebUtils.microsoftLogin((idToken, accessToken) { print('## RESULT: acces: $accessToken id: $idToken'); - }); - /* + /* store.dispatch(OAuthLoginRequest( completer: completer, idToken: idToken, @@ -240,6 +239,9 @@ class LoginVM { )); completer.future.then((_) => _handleLogin(context: context)); */ + }, (dynamic error) { + completer.completeError(error); + }); } catch (error) { completer.completeError(error); print('## onMicrosoftLoginPressed: $error'); @@ -249,19 +251,17 @@ class LoginVM { (BuildContext context, Completer completer) async { try { WebUtils.microsoftLogin((idToken, accessToken) { - print('## RESULT: acces: $accessToken id: $idToken'); + store.dispatch(OAuthSignUpRequest( + completer: completer, + idToken: idToken, + provider: UserEntity.OAUTH_PROVIDER_MICROSOFT, + accessToken: accessToken, + )); + completer.future + .then((_) => _handleLogin(context: context, isSignUp: true)); + }, (dynamic error) { + completer.completeError(error); }); - - /* - store.dispatch(OAuthSignUpRequest( - completer: completer, - idToken: idToken, - provider: kOAuthProviderMicrosoft, - accessToken: accessToken, - )); - completer.future - .then((_) => _handleLogin(context: context, isSignUp: true)); - */ } catch (error) { completer.completeError(error); print('## onMicrosoftSignUpPressed: $error'); diff --git a/lib/ui/settings/user_details_vm.dart b/lib/ui/settings/user_details_vm.dart index 281761df4..87ec05a07 100644 --- a/lib/ui/settings/user_details_vm.dart +++ b/lib/ui/settings/user_details_vm.dart @@ -271,6 +271,8 @@ class UserDetailsVM { completer: completer, ), ); + }, (dynamic error) { + showErrorDialog(context: context, message: error); }); } catch (error) { showErrorDialog(context: context, message: error); diff --git a/lib/utils/web.dart b/lib/utils/web.dart index aa6fdacba..a82108e6e 100644 --- a/lib/utils/web.dart +++ b/lib/utils/web.dart @@ -69,7 +69,10 @@ class WebUtils { }); } - static void microsoftLogin(Function(String, String) callback) async { + static void microsoftLogin( + Function(String, String) succesCallback, + Function(dynamic) failureCallback, + ) async { final config = Configuration() ..auth = (BrowserAuthOptions() //..redirectUri = 'https://invoicing.co/auth/microsoft' @@ -81,10 +84,11 @@ class WebUtils { final loginRequest = PopupRequest()..scopes = ['user.read']; - final AuthenticationResult result = - await publicClientApp.loginPopup(loginRequest); - - callback(result?.idToken, result?.accessToken); + publicClientApp.loginPopup(loginRequest).then((result) { + succesCallback(result?.idToken, result?.accessToken); + }).catchError((dynamic error) { + failureCallback(error); + }); } /* diff --git a/lib/utils/web_stub.dart b/lib/utils/web_stub.dart index a8f28f97f..58b0cafff 100644 --- a/lib/utils/web_stub.dart +++ b/lib/utils/web_stub.dart @@ -24,7 +24,10 @@ class WebUtils { static void warnChanges(Store store) {} - static void microsoftLogin(Function(String, String) callback) async {} + static void microsoftLogin( + Function(String, String) successCallback, + Function(dynamic) failureCallback, + ) async {} /* static String loadToken() => null;