How to use the @accounts/common.validators.validateUsername function in @accounts/common

To help you get started, we’ve selected a few @accounts/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github accounts-js / accounts / packages / client / src / AccountsClient.js View on Github external
'Unrecognized options for create user request',
        {
          username: user && user.username,
          email: user && user.email,
        },
        400,
      );
    }

    // In case where password is an object we assume it was prevalidated and hashed
    if (!user.password ||
        (isString(user.password) && !validators.validatePassword(user.password))) {
      throw new AccountsError('Password is required');
    }

    if (!validators.validateUsername(user.username) && !validators.validateEmail(user.email)) {
      throw new AccountsError('Username or Email is required');
    }

    const hashAlgorithm = this.options.passwordHashAlgorithm;
    const password = (user.password && hashAlgorithm) ?
      hashPassword(user.password, hashAlgorithm) : user.password;
    const userToCreate = { ...user, password };
    try {
      const userId = await this.transport.createUser(userToCreate);
      const { onUserCreated } = this.options;
      if (callback && isFunction(callback)) {
        callback();
      }
      if (isFunction(onUserCreated)) {
        try {
          await onUserCreated({ id: userId });

@accounts/common

Fullstack authentication and accounts-management

MIT
Latest version published 7 years ago

Package Health Score

54 / 100
Full package analysis