tanutapi / dart_meteor

A Meteor DDP library for Dart/Flutter developers.
Other
37 stars 15 forks source link

Accounts-passwordless #46

Closed keepjhonnying closed 2 years ago

keepjhonnying commented 2 years ago

Hi;

Any tips on how to use the Accounts-passwordless [https://docs.meteor.com/packages/accounts-passwordless.html] package with this library?

tanutapi commented 2 years ago

You can do something like this. Create a new dart file and put the following code. I haven't test it yet. Please try it by yourself.

extension AccountsPasswordless on MeteorClient {
  Map<String, String> _transformSelector(dynamic selector) {
    if (selector is! String) {
      return selector;
    }

    if (selector.contains('@')) {
      return {'email': selector};
    }
    return {'username': selector};
  }

  Future<void> requestLoginTokenForUser(
    dynamic selector,
    Map<String, dynamic> userData,
    Map<String, dynamic> options,
  ) async {
    await call('requestLoginTokenForUser', args: [
      {
        'selector': _transformSelector(selector),
        'userData': userData,
        'options': options,
      }
    ]);
  }

  Future<MeteorClientLoginResult> passwordlessLoginWithToken(
    dynamic selector,
    String token,
  ) async {
    return await login({
      'selector': _transformSelector(selector),
      'token': token,
    });
  }
}
keepjhonnying commented 2 years ago

Thank you @tanutapi for your time and response. I`ll try!

keepjhonnying commented 2 years ago

It works perfectly @tanutapi. Thank u!!!