Basic Userdata storage
This commit is contained in:
parent
ac32d2419d
commit
955a01d368
1 changed files with 38 additions and 0 deletions
38
lib/backend/storage.dart
Normal file
38
lib/backend/storage.dart
Normal file
|
@ -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<LoginDetails> 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<Map<String, dynamic>?> getRooms() async {
|
||||
final db = Localstore.instance;
|
||||
return await db.collection('rooms').get();
|
||||
}
|
Loading…
Reference in a new issue