add proper logging
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/user.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/domain/services/login.service.dart';
|
||||
import 'package:immich_mobile/domain/store_manager.dart';
|
||||
import 'package:immich_mobile/domain/services/user.service.dart';
|
||||
import 'package:immich_mobile/i18n/strings.g.dart';
|
||||
import 'package:immich_mobile/presentation/modules/common/states/server_info/server_feature_config.state.dart';
|
||||
import 'package:immich_mobile/presentation/modules/login/models/login_page.model.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/utils/immich_auth_interceptor.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
|
||||
import 'package:immich_mobile/utils/snackbar_manager.dart';
|
||||
import 'package:openapi/openapi.dart';
|
||||
|
||||
class LoginPageCubit extends Cubit<LoginPageState> with LogContext {
|
||||
LoginPageCubit() : super(LoginPageState.reset());
|
||||
@@ -60,8 +65,8 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogContext {
|
||||
// Check for /.well-known/immich
|
||||
url = await loginService.resolveEndpoint(uri);
|
||||
|
||||
di<StoreManager>().put(StoreKey.serverEndpoint, url);
|
||||
ServiceLocator.registerPostValidationServices(url);
|
||||
di<IStoreRepository>().set(StoreKey.serverEndpoint, url);
|
||||
await ServiceLocator.registerPostValidationServices(url);
|
||||
|
||||
// Fetch server features
|
||||
await di<ServerFeatureConfigCubit>().getFeatures();
|
||||
@@ -76,15 +81,64 @@ class LoginPageCubit extends Cubit<LoginPageState> with LogContext {
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
emit(state.copyWith(isValidationInProgress: true));
|
||||
try {
|
||||
emit(state.copyWith(isValidationInProgress: true));
|
||||
final accessToken =
|
||||
await di<LoginService>().passwordLogin(email, password);
|
||||
|
||||
final url = di<StoreManager>().get(StoreKey.serverEndpoint);
|
||||
if (accessToken == null) {
|
||||
SnackbarManager.showError(t.login.error.error_login);
|
||||
return;
|
||||
}
|
||||
|
||||
await _postLogin(accessToken);
|
||||
} finally {
|
||||
emit(state.copyWith(isValidationInProgress: false));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> oAuthLogin() async {
|
||||
emit(state.copyWith(isValidationInProgress: true));
|
||||
try {
|
||||
emit(state.copyWith(isValidationInProgress: true));
|
||||
|
||||
final url = di<StoreManager>().get(StoreKey.serverEndpoint);
|
||||
final accessToken = await di<LoginService>().oAuthLogin();
|
||||
|
||||
if (accessToken == null) {
|
||||
SnackbarManager.showError(t.login.error.error_login_oauth);
|
||||
return;
|
||||
}
|
||||
|
||||
await _postLogin(accessToken);
|
||||
} finally {
|
||||
emit(state.copyWith(isValidationInProgress: false));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _postLogin(String accessToken) async {
|
||||
await di<IStoreRepository>().set(StoreKey.accessToken, accessToken);
|
||||
|
||||
/// Set token to interceptor
|
||||
final interceptor = di<Openapi>()
|
||||
.dio
|
||||
.interceptors
|
||||
.firstWhereOrNull((i) => i is ImmichAuthInterceptor)
|
||||
as ImmichAuthInterceptor?;
|
||||
interceptor?.setAccessToken(accessToken);
|
||||
|
||||
final user = await di<UserService>().getMyUser();
|
||||
if (user == null) {
|
||||
SnackbarManager.showError(t.login.error.error_login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Register user
|
||||
ServiceLocator.registerCurrentUser(user);
|
||||
await di<IUserRepository>().insertUser(user);
|
||||
|
||||
emit(state.copyWith(
|
||||
isValidationInProgress: false,
|
||||
isServerValidated: true,
|
||||
));
|
||||
}
|
||||
|
||||
void resetServerValidation() {
|
||||
|
||||
Reference in New Issue
Block a user