fetchCredentials method

  1. @override
Future<PowerSyncCredentials?> fetchCredentials()

Get credentials for PowerSync.

This should always fetch a fresh set of credentials - don't use cached values.

Return null if the user is not signed in. Throw an error if credentials cannot be fetched due to a network error or other temporary error.

This token is kept for the duration of a sync connection.


Future<PowerSyncCredentials?> fetchCredentials() async {
  final devCredentials = await loadDevCredentials();
  if (devCredentials?.token == null) {
    // Not signed in
    return null;
  final uri = Uri.parse(devCredentials!.endpoint).resolve('dev/token.json');
  final res = await http
      .post(uri, headers: {'Authorization': 'Token ${devCredentials.token}'});
  if (res.statusCode == 401) {
  if (res.statusCode != 200) {
    throw HttpException(res.reasonPhrase ?? 'Request failed', uri: uri);

  return PowerSyncCredentials.fromJson(jsonDecode(res.body)['data']);