From 662029a748157e72382cd6246d912a9b15dcc86f Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 20 Jun 2022 18:12:59 +0300 Subject: [PATCH 1/3] support App.deleteUser --- CHANGELOG.md | 1 + lib/src/app.dart | 5 +++++ lib/src/native/realm_core.dart | 14 ++++++++++++++ test/app_test.dart | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c3209e8..5e94043cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * 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. ([#](https://github.com/realm/realm-dart/pull/)) ## 0.3.1+beta (2022-06-07) diff --git a/lib/src/app.dart b/lib/src/app.dart index 6aeaa98ae..c94f82515 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -150,6 +150,11 @@ class App { return await realmCore.removeUser(this, user); } + /// Deletes a user and all its data from the server. + Future 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); diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 65f0db32c..a51b19438 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -1611,6 +1611,20 @@ class _RealmCore { throw UnsupportedError("Platform ${Platform.operatingSystem} is not supported"); } + + Future deleteUser(App app, User user) { + final completer = Completer(); + _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 { diff --git a/test/app_test.dart b/test/app_test.dart index 93afc1a16..88e707a1a 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -210,6 +210,22 @@ Future main([List? 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("invalid username/password")); + }); } Future testLogger( From 3a701c54bc034ef6b399bc0cab09f3f40474cf6b Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 20 Jun 2022 18:15:52 +0300 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e94043cd..1eebded77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ * 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. ([#](https://github.com/realm/realm-dart/pull/)) +* Support `App.deleteUser ` for deleting user accounts. ([#679](https://github.com/realm/realm-dart/pull/679)) ## 0.3.1+beta (2022-06-07) From 8ea37da034a09172ee3e6d848d4e25248463ec13 Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 20 Jun 2022 18:16:57 +0300 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eebded77..80c15c836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 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))