@@ -5,7 +5,6 @@ import 'package:path_provider/path_provider.dart';
5
5
import 'package:powersync/powersync.dart' ;
6
6
import 'package:wger/api_client.dart' ;
7
7
8
- import './app_config.dart' ;
9
8
import './models/schema.dart' ;
10
9
11
10
final log = Logger ('powersync-django' );
@@ -24,10 +23,13 @@ final List<RegExp> fatalResponseCodes = [
24
23
25
24
class DjangoConnector extends PowerSyncBackendConnector {
26
25
PowerSyncDatabase db;
26
+ String baseUrl;
27
+ String powersyncUrl;
28
+ late ApiClient apiClient;
27
29
28
- DjangoConnector (this .db);
29
-
30
- final ApiClient apiClient = const ApiClient ( AppConfig .djangoUrl);
30
+ DjangoConnector (this .db, this .baseUrl, this .powersyncUrl) {
31
+ apiClient = ApiClient (baseUrl);
32
+ }
31
33
32
34
/// Get a token to authenticate against the PowerSync instance.
33
35
@override
@@ -37,7 +39,7 @@ class DjangoConnector extends PowerSyncBackendConnector {
37
39
// final wgerSession = await apiClient.getWgerJWTToken();
38
40
final session = await apiClient.getPowersyncToken ();
39
41
// note: we don't set userId and expires property here. not sure if needed
40
- return PowerSyncCredentials (endpoint: AppConfig .powersyncUrl, token: session['token' ]);
42
+ return PowerSyncCredentials (endpoint: this .powersyncUrl, token: session['token' ]);
41
43
}
42
44
43
45
// Upload pending changes to Postgres via Django backend
@@ -92,7 +94,7 @@ Future<String> getDatabasePath() async {
92
94
}
93
95
94
96
// opens the database and connects if logged in
95
- Future <void > openDatabase (bool connect) async {
97
+ Future <void > openDatabase (bool connect, String baseUrl, String powersyncUrl ) async {
96
98
// Open the local database
97
99
if (! _dbInitialized) {
98
100
db = PowerSyncDatabase (schema: schema, path: await getDatabasePath (), logger: attachedLogger);
@@ -103,7 +105,8 @@ Future<void> openDatabase(bool connect) async {
103
105
if (connect) {
104
106
// If the user is already logged in, connect immediately.
105
107
// Otherwise, connect once logged in.
106
- final currentConnector = DjangoConnector (db);
108
+
109
+ final currentConnector = DjangoConnector (db, baseUrl, powersyncUrl);
107
110
db.connect (connector: currentConnector);
108
111
109
112
// TODO: should we respond to login state changing? like here:
0 commit comments