✨ Send delete session requset when logout
This commit is contained in:
@@ -3,12 +3,14 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:island/pods/network.dart';
|
||||||
import 'package:island/pods/userinfo.dart';
|
import 'package:island/pods/userinfo.dart';
|
||||||
import 'package:island/screens/notification.dart';
|
import 'package:island/screens/notification.dart';
|
||||||
import 'package:island/services/responsive.dart';
|
import 'package:island/services/responsive.dart';
|
||||||
import 'package:island/widgets/account/account_name.dart';
|
import 'package:island/widgets/account/account_name.dart';
|
||||||
import 'package:island/widgets/account/status.dart';
|
import 'package:island/widgets/account/status.dart';
|
||||||
import 'package:island/widgets/account/leveling_progress.dart';
|
import 'package:island/widgets/account/leveling_progress.dart';
|
||||||
|
import 'package:island/widgets/alert.dart';
|
||||||
import 'package:island/widgets/app_scaffold.dart';
|
import 'package:island/widgets/app_scaffold.dart';
|
||||||
import 'package:island/widgets/content/cloud_files.dart';
|
import 'package:island/widgets/content/cloud_files.dart';
|
||||||
import 'package:island/widgets/debug_sheet.dart';
|
import 'package:island/widgets/debug_sheet.dart';
|
||||||
@@ -303,7 +305,12 @@ class AccountScreen extends HookConsumerWidget {
|
|||||||
trailing: const Icon(Symbols.chevron_right),
|
trailing: const Icon(Symbols.chevron_right),
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||||
title: Text('logout').tr(),
|
title: Text('logout').tr(),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
|
final apiClient = ref.watch(apiClientProvider);
|
||||||
|
showLoadingModal(context);
|
||||||
|
await apiClient.delete('/id/accounts/me/sessions/current');
|
||||||
|
if (!context.mounted) return;
|
||||||
|
hideLoadingModal(context);
|
||||||
final userNotifier = ref.read(userInfoProvider.notifier);
|
final userNotifier = ref.read(userInfoProvider.notifier);
|
||||||
userNotifier.logOut();
|
userNotifier.logOut();
|
||||||
},
|
},
|
||||||
|
@@ -42,6 +42,22 @@ final Map<int, (String, String, IconData)> kFactorTypes = {
|
|||||||
4: ('authFactorPin', 'authFactorPinDescription', Symbols.nest_secure_alarm),
|
4: ('authFactorPin', 'authFactorPinDescription', Symbols.nest_secure_alarm),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Future<String?> getDeviceName() async {
|
||||||
|
if (kIsWeb) return null;
|
||||||
|
String? name;
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
final deviceInfo = await DeviceInfoPlugin().iosInfo;
|
||||||
|
name = deviceInfo.name;
|
||||||
|
} else if (Platform.isAndroid) {
|
||||||
|
final deviceInfo = await DeviceInfoPlugin().androidInfo;
|
||||||
|
name = deviceInfo.name;
|
||||||
|
} else if (Platform.isWindows) {
|
||||||
|
final deviceInfo = await DeviceInfoPlugin().windowsInfo;
|
||||||
|
name = deviceInfo.computerName;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
class LoginScreen extends HookConsumerWidget {
|
class LoginScreen extends HookConsumerWidget {
|
||||||
const LoginScreen({super.key});
|
const LoginScreen({super.key});
|
||||||
|
|
||||||
@@ -198,28 +214,6 @@ class _LoginCheckScreen extends HookConsumerWidget {
|
|||||||
wsNotifier.connect();
|
wsNotifier.connect();
|
||||||
if (context.mounted) Navigator.pop(context, true);
|
if (context.mounted) Navigator.pop(context, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the sessions' device name is available
|
|
||||||
if (!kIsWeb) {
|
|
||||||
String? name;
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
final deviceInfo = await DeviceInfoPlugin().iosInfo;
|
|
||||||
name = deviceInfo.name;
|
|
||||||
} else if (Platform.isAndroid) {
|
|
||||||
final deviceInfo = await DeviceInfoPlugin().androidInfo;
|
|
||||||
name = deviceInfo.name;
|
|
||||||
} else if (Platform.isWindows) {
|
|
||||||
final deviceInfo = await DeviceInfoPlugin().windowsInfo;
|
|
||||||
name = deviceInfo.computerName;
|
|
||||||
}
|
|
||||||
if (name != null) {
|
|
||||||
final client = ref.watch(apiClientProvider);
|
|
||||||
await client.patch(
|
|
||||||
'/id/accounts/me/sessions/current/label',
|
|
||||||
data: jsonEncode(name),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
@@ -578,6 +572,7 @@ class _LoginLookupScreen extends HookConsumerWidget {
|
|||||||
data: {
|
data: {
|
||||||
'account': uname,
|
'account': uname,
|
||||||
'device_id': await getUdid(),
|
'device_id': await getUdid(),
|
||||||
|
'device_name': await getDeviceName(),
|
||||||
'platform':
|
'platform':
|
||||||
kIsWeb
|
kIsWeb
|
||||||
? 1
|
? 1
|
||||||
@@ -628,6 +623,7 @@ class _LoginLookupScreen extends HookConsumerWidget {
|
|||||||
'identity_token': credential.identityToken!,
|
'identity_token': credential.identityToken!,
|
||||||
'authorization_code': credential.authorizationCode,
|
'authorization_code': credential.authorizationCode,
|
||||||
'device_id': await getUdid(),
|
'device_id': await getUdid(),
|
||||||
|
'device_name': await getDeviceName(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user