ft/adds session reset and client.account
This commit is contained in:
parent
4887e0fd4d
commit
b7a189e409
@ -28,7 +28,7 @@ class Session {
|
||||
|
||||
Future<Database> get database async => _database;
|
||||
|
||||
static Future<Session> get newSession async {
|
||||
static Future<Session> get session async {
|
||||
final Database db = await openDatabase(
|
||||
join(await getDatabasesPath(), 'df_database.db'),
|
||||
onCreate: (db, version) {
|
||||
@ -47,6 +47,17 @@ class Session {
|
||||
_initDatabase();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
if (sessionId != null) {
|
||||
removeSession(sessionId!);
|
||||
}
|
||||
sessionId = null;
|
||||
accessToken = null;
|
||||
refreshToken = null;
|
||||
accessTokenExpiresAt = null;
|
||||
refreshTokenExpiresAt = null;
|
||||
}
|
||||
|
||||
Future<Database> _initDatabase() async {
|
||||
// print('DB: INITIALIZING - start');
|
||||
_database = await openDatabase(
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:app/data/database.dart';
|
||||
import 'package:app/pb/account.pb.dart';
|
||||
import 'package:app/pb/rpc_create_account.pb.dart';
|
||||
import 'package:app/pb/rpc_get_account_info.pb.dart';
|
||||
import 'package:app/pb/rpc_login.pb.dart';
|
||||
@ -17,9 +18,10 @@ class GClient {
|
||||
Map<String, String> metadata = {'Authorization': ''};
|
||||
|
||||
late Session session;
|
||||
late Account account;
|
||||
|
||||
static Future<GClient> get client async {
|
||||
Session s = await Session.newSession;
|
||||
Session s = await Session.session;
|
||||
GClient c = GClient();
|
||||
c.session = s;
|
||||
final sessions = await c.session.getSessions();
|
||||
@ -43,7 +45,7 @@ class GClient {
|
||||
Future<void> main(List<String> args) async {}
|
||||
|
||||
void _init() async {
|
||||
session = await Session.newSession;
|
||||
session = await Session.session;
|
||||
|
||||
final sessions = await session.getSessions();
|
||||
if (sessions.isNotEmpty) {
|
||||
@ -60,6 +62,7 @@ class GClient {
|
||||
email: email,
|
||||
password: password,
|
||||
));
|
||||
account = response.account;
|
||||
return response;
|
||||
} on GrpcError catch (e) {
|
||||
onError(error: e);
|
||||
@ -110,10 +113,9 @@ class GClient {
|
||||
session.accessTokenExpiresAt!.toDateTime().isAfter(DateTime.now());
|
||||
|
||||
Future<void> resetSession() async {
|
||||
if (session.sessionId != null) {
|
||||
session.removeSession(session.sessionId!);
|
||||
}
|
||||
session = await Session.newSession;
|
||||
session.reset();
|
||||
account = Account();
|
||||
session = await Session.session;
|
||||
}
|
||||
|
||||
Future<bool> refreshToken() async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user