Skip to content

Crash if i login #335

@TillJohanndeiter

Description

@TillJohanndeiter

I upgraded to powersync: ^1.16.0, and downloaded via dart run powersync:setup_web the new setup.

Then i get this error on web when i login. On the linux build everything works fine.

[PowerSync] FINE: 2025-10-03 16:31:16.678: [in] SyncWorkerMessageType.logEvent
[PowerSync] INFO: 2025-10-03 16:31:16.678: [Sync Worker]: [PowerSync] FINE: 2025-10-03 16:31:16.677: Broadcasting sync event: SyncStatus<connected: true connecting: false downloading: true (progress: for total: 4992 / 4992) uploading: false lastSyncedAt: null, hasSynced: null, error: null>
[PowerSync] FINE: 2025-10-03 16:31:16.679: [in] SyncWorkerMessageType.notifySyncStatus
DartError: TypeError: null: type 'Null' is not a subtype of type 'List<dynamic>'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3       throw_
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1503:3                              _generalAsCheckImplementation
package:powersync_core/src/web/sync_worker_protocol.dart 334:14                   <fn>
package:powersync_core/src/web/sync_worker_protocol.dart 331:26                   SerializedSyncStatus.asSyncStatus
package:powersync_core/src/web/sync_controller.dart 76:55                         <fn>
dart-sdk/lib/async/zone.dart 1778:9                                               runUnaryGuarded
dart-sdk/lib/async/stream_impl.dart 381:5                                         [_sendData]
dart-sdk/lib/async/stream_impl.dart 573:13                                        perform
dart-sdk/lib/async/stream_impl.dart 678:10                                        handleNext
dart-sdk/lib/async/stream_impl.dart 649:7                                         <fn>
dart-sdk/lib/async/schedule_microtask.dart 40:34                                  _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77  tear
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 188:69               <fn>
[PowerSync] FINE: 2025-10-03 16:31:16.957: [in] SyncWorkerMessageType.logEvent
[PowerSync] INFO: 2025-10-03 16:31:16.958: [Sync Worker]: [PowerSync] FINE: 2025-10-03 16:31:16.957: validated checkpoint: Instance of 'minified:cX'
[PowerSync] FINE: 2025-10-03 16:31:16.959: [in] SyncWorkerMessageType.logEvent
[PowerSync] INFO: 2025-10-03 16:31:16.959: [Sync Worker]: [PowerSync] FINE: 2025-10-03 16:31:16.958: Broadcasting sync event: SyncStatus<connected: true connecting: false downloading: false (progress: null) uploading: false lastSyncedAt: 2025-10-03 16:31:16.957, hasSynced: null, error: null>
[PowerSync] FINE: 2025-10-03 16:31:16.959: [in] SyncWorkerMessageType.notifySyncStatus
DartError: TypeError: null: type 'Null' is not a subtype of type 'List<dynamic>'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 274:3       throw_
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1503:3                              _generalAsCheckImplementation
package:powersync_core/src/web/sync_worker_protocol.dart 334:14                   <fn>
package:powersync_core/src/web/sync_worker_protocol.dart 331:26                   SerializedSyncStatus.asSyncStatus
package:powersync_core/src/web/sync_controller.dart 76:55                         <fn>
dart-sdk/lib/async/zone.dart 1778:9                                               runUnaryGuarded
dart-sdk/lib/async/stream_impl.dart 381:5                                         [_sendData]
dart-sdk/lib/async/stream_impl.dart 573:13                                        perform
dart-sdk/lib/async/stream_impl.dart 678:10                                        handleNext
dart-sdk/lib/async/stream_impl.dart 649:7                                         <fn>
dart-sdk/lib/async/schedule_microtask.dart 40:34                                  _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 118:77  tear
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 188:69       

Here is my powersync service

Future<void> openPowerSyncDatabase() async {
  db = PowerSyncDatabase(schema: schema, path: await getDatabasePath());
  await db.initialize();
  PowerSyncSupabaseConnector? currentConnector;

  if (isLoggedIn()) {
    currentConnector = PowerSyncSupabaseConnector();
    await db.connect(connector: currentConnector);
  }

  Supabase.instance.client.auth.onAuthStateChange.listen((data) async {
    final AuthChangeEvent event = data.event;
    if (event == AuthChangeEvent.signedIn) {
      currentConnector = PowerSyncSupabaseConnector();
      await db.connect(connector: currentConnector!);
    } else if (event == AuthChangeEvent.signedOut) {
      currentConnector = null;
      await db.disconnect();
    } else if (event == AuthChangeEvent.tokenRefreshed) {
      await currentConnector?.prefetchCredentials();
    }
  });
}


class PowerSyncSupabaseConnector extends PowerSyncBackendConnector {
  Future<void>? _refreshFuture;

  PowerSyncSupabaseConnector();

  @override
  Future<PowerSyncCredentials?> fetchCredentials() async {
    await _refreshFuture;

    final session = Supabase.instance.client.auth.currentSession;
    if (session == null) {
      return null;
    }

    final token = session.accessToken;
....

    return PowerSyncCredentials(
        endpoint: powerSyncUrl,
        token: token,
        userId: userId,
        expiresAt: expiresAt);
  }

  @override
  void invalidateCredentials() {
    _refreshFuture = Supabase.instance.client.auth
        .refreshSession()
        .timeout(const Duration(seconds: 5))
        .then((response) => null, onError: (error) => null);
  }

  // Upload pending changes to Supabase.
  @override
  Future<void> uploadData(PowerSyncDatabase database) async {

I already tried to clear the cache. If i downgrade everything works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions