From 4fba75778fb3433efd1bbac389bcfb1a6f6c5e9f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 13 Sep 2024 22:34:49 +0300 Subject: [PATCH 1/2] small cleanups & clarifications --- demos/django-todolist/lib/powersync.dart | 27 ++++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/demos/django-todolist/lib/powersync.dart b/demos/django-todolist/lib/powersync.dart index bc6ecbb1..07f90f58 100644 --- a/demos/django-todolist/lib/powersync.dart +++ b/demos/django-todolist/lib/powersync.dart @@ -34,8 +34,7 @@ class DjangoConnector extends PowerSyncBackendConnector { /// Get a token to authenticate against the PowerSync instance. @override Future fetchCredentials() async { - final prefs = await SharedPreferences.getInstance(); - final userId = prefs.getString('id'); + final userId = await getUserId(); if (userId == null) { throw Exception('User does not have session'); } @@ -90,14 +89,15 @@ late final PowerSyncDatabase db; // Hacky flag to ensure the database is only initialized once, better to do this with listeners bool _dbInitialized = false; +/// id of the user currently logged in +Future getUserId() async { + final prefs = await SharedPreferences.getInstance(); + return prefs.getString('id'); +} + Future isLoggedIn() async { - final prefs = - await SharedPreferences.getInstance(); // Initialize SharedPreferences - final userId = prefs.getString('id'); - if (userId != null) { - return true; - } - return false; + final userId = await getUserId(); + return userId != null; } Future getDatabasePath() async { @@ -105,6 +105,7 @@ Future getDatabasePath() async { return join(dir.path, 'powersync-demo.db'); } +// opens the database and connects if logged in Future openDatabase() async { // Open the local database if (!_dbInitialized) { @@ -122,7 +123,7 @@ Future openDatabase() async { if (await isLoggedIn()) { // If the user is already logged in, connect immediately. - // Otherwise, connect once logged in. + // Otherwise, the LoginPage will connect once logged in. currentConnector = DjangoConnector(db); db.connect(connector: currentConnector); } @@ -132,9 +133,3 @@ Future openDatabase() async { Future logout() async { await db.disconnectAndClear(); } - -/// id of the user currently logged in -Future getUserId() async { - final prefs = await SharedPreferences.getInstance(); - return prefs.getString('id'); -} From e879edda83aafc2fd3bccfd96d945d0b6f434dac Mon Sep 17 00:00:00 2001 From: DominicGBauer Date: Thu, 26 Sep 2024 06:40:04 +0200 Subject: [PATCH 2/2] chore: update podlock --- demos/django-todolist/ios/Podfile.lock | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/demos/django-todolist/ios/Podfile.lock b/demos/django-todolist/ios/Podfile.lock index 2e9ceff2..49f7e3e1 100644 --- a/demos/django-todolist/ios/Podfile.lock +++ b/demos/django-todolist/ios/Podfile.lock @@ -3,25 +3,28 @@ PODS: - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS - - powersync-sqlite-core (0.1.6) + - powersync-sqlite-core (0.2.1) - powersync_flutter_libs (0.0.1): - Flutter - - powersync-sqlite-core (~> 0.1.6) + - powersync-sqlite-core (~> 0.2.1) - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS - - "sqlite3 (3.46.0+1)": - - "sqlite3/common (= 3.46.0+1)" - - "sqlite3/common (3.46.0+1)" - - "sqlite3/fts5 (3.46.0+1)": + - "sqlite3 (3.46.1+1)": + - "sqlite3/common (= 3.46.1+1)" + - "sqlite3/common (3.46.1+1)" + - "sqlite3/dbstatvtab (3.46.1+1)": - sqlite3/common - - "sqlite3/perf-threadsafe (3.46.0+1)": + - "sqlite3/fts5 (3.46.1+1)": - sqlite3/common - - "sqlite3/rtree (3.46.0+1)": + - "sqlite3/perf-threadsafe (3.46.1+1)": + - sqlite3/common + - "sqlite3/rtree (3.46.1+1)": - sqlite3/common - sqlite3_flutter_libs (0.0.1): - Flutter - - sqlite3 (~> 3.46.0) + - "sqlite3 (~> 3.46.0+1)" + - sqlite3/dbstatvtab - sqlite3/fts5 - sqlite3/perf-threadsafe - sqlite3/rtree @@ -52,12 +55,12 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c - powersync-sqlite-core: 4c38c8f470f6dca61346789fd5436a6826d1e3dd - powersync_flutter_libs: 5d6b132a398de442c0853a8b14bfbb62cd4ff5a1 - shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 - sqlite3: 292c3e1bfe89f64e51ea7fc7dab9182a017c8630 - sqlite3_flutter_libs: 0d611efdf6d1c9297d5ab03dab21b75aeebdae31 + path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 + powersync-sqlite-core: 38ead13d8b21920cfbc79e9b3415b833574a506d + powersync_flutter_libs: 9d26987384a376a18879b9d4fa71629407683163 + shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 + sqlite3: 0bb0e6389d824e40296f531b858a2a0b71c0d2fb + sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b PODFILE CHECKSUM: f7b3cb7384a2d5da4b22b090e1f632de7f377987