Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support App.deleteUser #679

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## vNext

**This project is in the Beta stage. The API should be quite stable, but occasional breaking changes may be made.**

### Enhancements
* Added `DisconnectedSyncConfiguration` for opening a synchronized realm in a disconnected state. This configuration allows a synchronized realm to be opened by a secondary process, while a primary process handles synchronization. ([#621](https://github.com/realm/realm-dart/pull/621))
* Support better default paths on Flutter. ([#665](https://github.com/realm/realm-dart/pull/665))
* Support `Configuration.defaultRealmName` for setting the default realm name. ([#665](https://github.com/realm/realm-dart/pull/665))
* Support `Configuration.defaultRealmPath` for setting a custom default path for realms. ([#665](https://github.com/realm/realm-dart/pull/665))
* Support `Configuration.defaultStoragePath ` for getting the platform specific storage paths. ([#665](https://github.com/realm/realm-dart/pull/665))
* Support `App.deleteUser ` for deleting user accounts. ([#679](https://github.com/realm/realm-dart/pull/679))

## 0.3.1+beta (2022-06-07)

Expand Down
5 changes: 5 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ class App {
return await realmCore.removeUser(this, user);
}

/// Deletes a user and all its data from the server.
Future<void> deleteUser(User user) async {
return await realmCore.deleteUser(this, user);
}

/// Switches the [currentUser] to the one specified in [user].
void switchUser(User user) {
realmCore.switchUser(this, user);
Expand Down
14 changes: 14 additions & 0 deletions lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,20 @@ class _RealmCore {

throw UnsupportedError("Platform ${Platform.operatingSystem} is not supported");
}

Future<void> deleteUser(App app, User user) {
final completer = Completer<void>();
_realmLib.invokeGetBool(
() => _realmLib.realm_app_delete_user(
app.handle._pointer,
user.handle._pointer,
Pointer.fromFunction(void_completion_callback),
completer.toPersistentHandle(),
_realmLib.addresses.realm_dart_delete_persistent_handle,
),
"Delete user failed");
return completer.future;
}
}

class LastError {
Expand Down
16 changes: 16 additions & 0 deletions test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ Future<void> main([List<String>? args]) async {
},
);
});

baasTest('App delete user', (configuration) async {
final app = App(configuration);
final authProvider = EmailPasswordAuthProvider(app);
String username = "realm_tests_do_autoverify${generateRandomString(5)}@realm.io";
const String strongPassword = "SWV23R#@T#VFQDV";
await authProvider.registerUser(username, strongPassword);
final user = await loginWithRetry(app, Credentials.emailPassword(username, strongPassword));
expect(user, isNotNull);
expect(user.state, UserState.loggedIn);

await app.deleteUser(user);
expect(user.state, UserState.removed);

expect(() async => await loginWithRetry(app, Credentials.emailPassword(username, strongPassword)), throws<RealmException>("invalid username/password"));
});
}

Future<void> testLogger(
Expand Down