This commit is contained in:
2023-08-30 14:44:58 +08:00
parent 8c655b0fd5
commit 6884beaf3d
14 changed files with 327 additions and 33 deletions

27
lib/auth.dart Normal file
View File

@@ -0,0 +1,27 @@
import 'api/status.dart';
import 'api/user.dart';
import 'globals.dart';
class AuthInfo {
AuthInfo();
BUser? _user;
BUser? get user => _user;
ServerStatus? _status;
ServerStatus? get status => _status;
bool get isAuthed => (_user != null);
Future<void> getServerStatus() async {
_status = (await api.getStatus()).unwrap();
}
Future<bool> checkAuth() async {
final re = await api.getUser();
if (re.ok) {
_user = re.data!;
} else {
_user = null;
}
await getServerStatus();
return re.ok;
}
}