Skip to content

Commit

Permalink
support switch user (#493)
Browse files Browse the repository at this point in the history
* support switch user

* update changelog

* don't ask for newUser value when switching users
  • Loading branch information
blagoev authored Apr 26, 2022
1 parent 97251d1 commit 5df0e8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ x.x.x Release notes (yyyy-MM-dd)
* Expose currentUser property on App. ([473](https://github.com/realm/realm-dart/pull/473))
* Support logout user. ([#476](https://github.com/realm/realm-dart/pull/476))
* Support remove user. ([#492](https://github.com/realm/realm-dart/pull/492))
* Support switch current user. ([#493](https://github.com/realm/realm-dart/pull/493))

### Fixed
* Fixed an issue that would result in the wrong transaction being rolled back if you start a write transaction inside a write transaction. ([#442](https://github.com/realm/realm-dart/issues/442))
Expand Down
5 changes: 5 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class App {
Future<void> removeUser(User user) async {
return await realmCore.removeUser(this, user);
}

/// Switches the [currentUser] to the one specified in [user].
void switchUser(User user) {
realmCore.switchUser(this, user);
}
}

/// @nodoc
Expand Down
12 changes: 12 additions & 0 deletions lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,18 @@ class _RealmCore {
"Remove user failed");
return completer.future;
}

void switchUser(App application, User user) {
return using((arena) {
_realmLib.invokeGetBool(
() => _realmLib.realm_app_switch_user(
application.handle._pointer,
user.handle._pointer,
nullptr,
),
"Switch user failed");
});
}
}

class LastError {
Expand Down

0 comments on commit 5df0e8b

Please sign in to comment.