@@ -3,7 +3,6 @@ import 'package:logging/logging.dart';
3
3
import 'package:path/path.dart' ;
4
4
import 'package:path_provider/path_provider.dart' ;
5
5
import 'package:powersync/powersync.dart' ;
6
- import 'package:shared_preferences/shared_preferences.dart' ;
7
6
import 'package:wger/api_client.dart' ;
8
7
9
8
import './app_config.dart' ;
@@ -37,6 +36,7 @@ class DjangoConnector extends PowerSyncBackendConnector {
37
36
// https://docs.powersync.com/usage/installation/authentication-setup/custom
38
37
// final wgerSession = await apiClient.getWgerJWTToken();
39
38
final session = await apiClient.getPowersyncToken ();
39
+ // note: we don't set userId and expires property here. not sure if needed
40
40
return PowerSyncCredentials (endpoint: AppConfig .powersyncUrl, token: session['token' ]);
41
41
}
42
42
@@ -86,37 +86,24 @@ late final PowerSyncDatabase db;
86
86
// Hacky flag to ensure the database is only initialized once, better to do this with listeners
87
87
bool _dbInitialized = false ;
88
88
89
- /// id of the user currently logged in
90
- Future <String ?> getUserId () async {
91
- final prefs = await SharedPreferences .getInstance ();
92
- return prefs.getString ('id' );
93
- }
94
-
95
- Future <bool > isLoggedIn () async {
96
- final userId = await getUserId ();
97
- return userId != null ;
98
- }
99
-
100
89
Future <String > getDatabasePath () async {
101
90
final dir = await getApplicationSupportDirectory ();
102
91
return join (dir.path, 'powersync-demo.db' );
103
92
}
104
93
105
94
// opens the database and connects if logged in
106
- Future <void > openDatabase () async {
95
+ Future <void > openDatabase (bool connect ) async {
107
96
// Open the local database
108
97
if (! _dbInitialized) {
109
98
db = PowerSyncDatabase (schema: schema, path: await getDatabasePath (), logger: attachedLogger);
110
99
await db.initialize ();
111
100
_dbInitialized = true ;
112
101
}
113
102
114
- DjangoConnector ? currentConnector;
115
-
116
- if (await isLoggedIn ()) {
103
+ if (connect) {
117
104
// If the user is already logged in, connect immediately.
118
105
// Otherwise, connect once logged in.
119
- currentConnector = DjangoConnector (db);
106
+ final currentConnector = DjangoConnector (db);
120
107
db.connect (connector: currentConnector);
121
108
122
109
// TODO: should we respond to login state changing? like here:
0 commit comments