From 955a01d3687f8df329082a169797941581c23730 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 17 Mar 2023 21:05:48 +0100 Subject: [PATCH] Basic Userdata storage --- lib/backend/storage.dart | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/backend/storage.dart diff --git a/lib/backend/storage.dart b/lib/backend/storage.dart new file mode 100644 index 0000000..d12a0e9 --- /dev/null +++ b/lib/backend/storage.dart @@ -0,0 +1,38 @@ +import 'package:localstore/localstore.dart'; +import './resolve_url.dart'; + +class LoginDetails { + const LoginDetails( + {required this.username, required this.password, required this.server}); + + final String username; + final String password; + final OutbagServer server; + + void toDisk() async { + final db = Localstore.instance; + await db + .collection('meta') + .doc('auth') + .set({'username': username, 'password': password}); + server.toDisk(); + } + + static Future fromDisk() async { + final db = Localstore.instance; + final data = await db.collection('meta').doc('auth').get(); + final server = await OutbagServer.fromDisk(); + + return LoginDetails( + username: data?['username'], + password: data?['password'], + server: server, + ); + } +} + +// obtain room list +Future?> getRooms() async { + final db = Localstore.instance; + return await db.collection('rooms').get(); +}