fix logOut failing, add invoking logOut before id server change

This commit is contained in:
csf 2022-12-16 23:18:30 +09:00
parent 9d2364b307
commit 3e8c1c46b6
3 changed files with 19 additions and 10 deletions

View File

@ -932,6 +932,10 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
return false;
}
}
final old = await bind.mainGetOption(key: 'custom-rendezvous-server');
if (old.isNotEmpty && old != idServer) {
await gFFI.userModel.logOut();
}
// should set one by one
await bind.mainSetOption(
key: 'custom-rendezvous-server', value: idServer);

View File

@ -261,6 +261,9 @@ void showServerSettingsWithValue(String id, String relay, String key,
});
if (await validate()) {
if (id != id0) {
if (id0.isNotEmpty) {
await gFFI.userModel.logOut();
}
bind.mainSetOption(key: "custom-rendezvous-server", value: id);
}
if (relay != relay0) {

View File

@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
import 'package:flutter_hbb/common/widgets/peer_tab_page.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
@ -78,15 +77,18 @@ class UserModel {
Future<void> logOut() async {
final tag = gFFI.dialogManager.showLoading(translate('Waiting'));
final url = await bind.mainGetApiServer();
final _ = await http.post(Uri.parse('$url/api/logout'),
body: {
'id': await bind.mainGetMyId(),
'uuid': await bind.mainGetUuid(),
},
headers: await getHttpHeaders());
await reset();
gFFI.dialogManager.dismissByTag(tag);
try {
final url = await bind.mainGetApiServer();
final _ = await http.post(Uri.parse('$url/api/logout'),
body: {
'id': await bind.mainGetMyId(),
'uuid': await bind.mainGetUuid(),
},
headers: await getHttpHeaders());
} finally {
await reset();
gFFI.dialogManager.dismissByTag(tag);
}
}
Future<Map<String, dynamic>> login(String userName, String pass) async {