Method: Firebase::Admin::Auth::UserManager#create_user

Defined in:
lib/firebase/admin/auth/user_manager.rb

#create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil) ⇒ UserRecord

Creates a new user account with the specified properties.

Parameters:

  • uid (String, nil) (defaults to: nil)

    The id to assign to the newly created user.

  • display_name (String, nil) (defaults to: nil)

    The user’s display name.

  • email (String, nil) (defaults to: nil)

    The user’s primary email.

  • email_verified (Boolean, nil) (defaults to: nil)

    A boolean indicating whether or not the user’s primary email is verified.

  • phone_number (String, nil) (defaults to: nil)

    The user’s primary phone number.

  • photo_url (String, nil) (defaults to: nil)

    The user’s photo URL.

  • password (String, nil) (defaults to: nil)

    The user’s raw, unhashed password.

  • disabled (Boolean, nil) (defaults to: nil)

    A boolean indicating whether or not the user account is disabled.

Returns:

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/firebase/admin/auth/user_manager.rb', line 34

def create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil)
  payload = {
    localId: validate_uid(uid),
    displayName: validate_display_name(display_name),
    email: validate_email(email),
    phoneNumber: validate_phone_number(phone_number),
    photoUrl: validate_photo_url(photo_url),
    password: validate_password(password),
    emailVerified: to_boolean(email_verified),
    disabled: to_boolean(disabled)
  }.compact
  res = @client.post(with_path("accounts"), payload).body
  uid = res&.fetch("localId")
  raise CreateUserError, "failed to create user #{res}" if uid.nil?
  get_user_by(uid: uid)
end