31a84b5ec7
This is prevents the current route from being reset, when reloading the tab and also prevents the welcome screen from showing (when running on slow connections) NOTE: This also means that the home screen will be loaded even if the client has never been logged in. This means that some functions might return null
38 lines
970 B
Dart
38 lines
970 B
Dart
import 'package:localstore/localstore.dart';
|
|
import './resolve_url.dart';
|
|
|
|
class User {
|
|
const User(
|
|
{required this.username, required this.password, required this.server});
|
|
|
|
final String username;
|
|
final String password;
|
|
final OutbagServer server;
|
|
|
|
Future<void> toDisk() async {
|
|
final db = Localstore.instance;
|
|
await db
|
|
.collection('meta')
|
|
.doc('auth')
|
|
.set({'username': username, 'password': password});
|
|
await server.toDisk();
|
|
}
|
|
|
|
static Future<User> fromDisk() async {
|
|
final db = Localstore.instance;
|
|
final data = await db.collection('meta').doc('auth').get();
|
|
final server = await OutbagServer.fromDisk();
|
|
|
|
return User(
|
|
username: data?['username'],
|
|
password: data?['password'],
|
|
server: server,
|
|
);
|
|
}
|
|
|
|
static listen(Function(Map<String, dynamic>) cb) async {
|
|
final db = Localstore.instance;
|
|
final stream = db.collection('meta').stream;
|
|
stream.listen(cb);
|
|
}
|
|
}
|