From b7a189e4090eea7454b5095db57b346993dbecf9 Mon Sep 17 00:00:00 2001 From: itsscb Date: Tue, 31 Oct 2023 23:00:21 +0100 Subject: [PATCH] ft/adds session reset and client.account --- frontend/app/lib/data/database.dart | 13 ++++++++++++- frontend/app/lib/gapi/client.dart | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/app/lib/data/database.dart b/frontend/app/lib/data/database.dart index f5d42d8..9cf0335 100644 --- a/frontend/app/lib/data/database.dart +++ b/frontend/app/lib/data/database.dart @@ -28,7 +28,7 @@ class Session { Future get database async => _database; - static Future get newSession async { + static Future 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 _initDatabase() async { // print('DB: INITIALIZING - start'); _database = await openDatabase( diff --git a/frontend/app/lib/gapi/client.dart b/frontend/app/lib/gapi/client.dart index eacc050..b52a466 100644 --- a/frontend/app/lib/gapi/client.dart +++ b/frontend/app/lib/gapi/client.dart @@ -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 metadata = {'Authorization': ''}; late Session session; + late Account account; static Future 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 main(List 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 resetSession() async { - if (session.sessionId != null) { - session.removeSession(session.sessionId!); - } - session = await Session.newSession; + session.reset(); + account = Account(); + session = await Session.session; } Future refreshToken() async {