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