setCredentials method

void setCredentials(
  1. SyncCredentials creds
)

Sets credentials to authenticate the client with the server.

Any credentials that were set before are replaced.

Usually, credentials are passed via the constructor, but this can be used to update them later, such as when a token expires.

Use the SyncCredentials factory methods to create credentials, for example SyncCredentials.jwtIdToken(idToken). The accepted credentials type depends on your Sync server configuration.

To pass multiple credentials, use setMultipleCredentials instead.

Implementation

void setCredentials(SyncCredentials creds) {
  if (creds is _SyncCredentialsNone) {
    checkObx(C.sync_credentials(_ptr, creds._type, nullptr, 0));
  } else if (creds is _SyncCredentialsUserPassword) {
    withNativeString(
        creds._user,
        (userCStr) => withNativeString(
            creds._password,
            (passwordCStr) => checkObx(C.sync_credentials_user_password(
                _ptr, creds._type, userCStr, passwordCStr))));
  } else if (creds is SyncCredentialsSecret) {
    withNativeBytes(
        creds.data,
        (Pointer<Uint8> credsPtr, int credsSize) => checkObx(
            C.sync_credentials(_ptr, creds._type, credsPtr, credsSize)));
  }
}