Skip to content

Commit

Permalink
support EmailPassword confirm user (#478)
Browse files Browse the repository at this point in the history
* support EmailPassword confirm user
* use persistent handle
Co-authored-by: Kasper Overgård Nielsen <[email protected]>
Co-authored-by: Desislava Stefanova <[email protected]>
Co-authored-by: Kasper Overgård Nielsen <[email protected]>
Co-authored-by: Desislava Stefanova <[email protected]>
  • Loading branch information
blagoev authored Apr 22, 2022
1 parent 0b482c5 commit a13fea2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ x.x.x Release notes (yyyy-MM-dd)
* Support ObjectId type. ([#468](https://github.com/realm/realm-dart/pull/468))
* Support Uuid type. ([#470](https://github.com/realm/realm-dart/pull/470))
* Support application login. ([#469](https://github.com/realm/realm-dart/pull/469))
* Support user registration with EmailPassword authentication provider. ([#452](https://github.com/realm/realm-dart/pull/452))
* Support EmailPassword register user. ([#452](https://github.com/realm/realm-dart/pull/452))
* Support EmailPassowrd confirm user. ([#478](https://github.com/realm/realm-dart/pull/478))

### 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
9 changes: 7 additions & 2 deletions lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class EmailPasswordAuthProvider {
/// The [password] to associate with the email. The password must be between 6 and 128 characters long.
///
/// Successful completion indicates that the user has been created on the server and can now be logged in with [Credentials.emailPassword()].
Future<void> registerUser(String email, String password) async {
return realmCore.appEmailPasswordRegisterUser(application, email, password);
Future<void> registerUser(String email, String password) {
return realmCore.emailPasswordRegisterUser(application, email, password);
}

/// Confirms a user with the given token and token id. These are typically included in the registration email.
Future<void> confirmUser(String token, String tokenId) {
return realmCore.emailPasswordConfirmUser(application, token, tokenId);
}
}
17 changes: 16 additions & 1 deletion lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ class _RealmCore {
completer.complete();
}

Future<void> appEmailPasswordRegisterUser(Application application, String email, String password) {
Future<void> emailPasswordRegisterUser(Application application, String email, String password) {
final completer = Completer<void>();
using((arena) {
_realmLib.invokeGetBool(() => _realmLib.realm_app_email_password_provider_client_register_email(
Expand All @@ -920,6 +920,21 @@ class _RealmCore {
});
return completer.future;
}

Future<void> emailPasswordConfirmUser(Application application, String token, String tokenId) {
final completer = Completer<void>();
using((arena) {
_realmLib.invokeGetBool(() => _realmLib.realm_app_email_password_provider_client_confirm_user(
application.handle._pointer,
token.toUtf8Ptr(arena),
tokenId.toUtf8Ptr(arena),
Pointer.fromFunction(void_completion_callback),
completer.toPersistentHandle(),
_deletePersistentHandleFuncPtr,
));
});
return completer.future;
}
}

class LastError {
Expand Down

0 comments on commit a13fea2

Please sign in to comment.