add device info at login
This commit is contained in:
@@ -4,6 +4,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/utils/device_info_service.dart';
|
||||
import '../../../common/utils/fcm_service.dart';
|
||||
import '../../../domain/auth/auth.dart';
|
||||
|
||||
part 'login_form_event.dart';
|
||||
@@ -13,7 +15,11 @@ part 'login_form_bloc.freezed.dart';
|
||||
@injectable
|
||||
class LoginFormBloc extends Bloc<LoginFormEvent, LoginFormState> {
|
||||
final IAuthRepository _repository;
|
||||
LoginFormBloc(this._repository) : super(LoginFormState.initial()) {
|
||||
final DeviceInfoService _deviceInfoService;
|
||||
final FcmService _fcmService;
|
||||
|
||||
LoginFormBloc(this._repository, this._deviceInfoService, this._fcmService)
|
||||
: super(LoginFormState.initial()) {
|
||||
on<LoginFormEvent>(_onLoginFormEvent);
|
||||
}
|
||||
|
||||
@@ -36,9 +42,25 @@ class LoginFormBloc extends Bloc<LoginFormEvent, LoginFormState> {
|
||||
final passwordValid = state.password.isNotEmpty;
|
||||
|
||||
if (emailValid && passwordValid) {
|
||||
// Ambil device info dan FCM token secara paralel
|
||||
final results = await Future.wait([
|
||||
_deviceInfoService.getDeviceInfo(),
|
||||
_fcmService.getToken(),
|
||||
]);
|
||||
|
||||
final deviceInfo = results[0] as DeviceInfo;
|
||||
final fcmToken = results[1] as String?;
|
||||
|
||||
failureOrAuth = await _repository.login(
|
||||
email: state.email,
|
||||
password: state.password,
|
||||
deviceId: deviceInfo.deviceId,
|
||||
deviceName: deviceInfo.deviceName,
|
||||
deviceType: deviceInfo.deviceType,
|
||||
platform: deviceInfo.platform,
|
||||
osVersion: deviceInfo.osVersion,
|
||||
appVersion: deviceInfo.appVersion,
|
||||
fcmToken: fcmToken,
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
|
||||
Reference in New Issue
Block a user