Skip to main content
Version: v2 RC

createUser()

Creates a new user. This function should only be called on a server. Never expose your service_role key in the browser.

const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' }
})

Parameters

  • AdminUserAttributesrequiredobject

    No description provided.

      Properties
    • app_metadataoptionalobject

      A custom data object to store the user's application specific metadata. This maps to the auth.users.app_metadata column.

      Only a service role can modify.

      The app_metadata should be a JSON object that includes app-specific info, such as identity providers, roles, and other access control information.

    • dataoptionalobject

      A custom data object to store the user's metadata. This maps to the auth.users.user_metadata column.

      The data should be a JSON object that includes user-specific info, such as their first and last name.

    • emailoptionalstring

      The user's email.

    • email_confirmoptionalboolean

      Confirms the user's email address if set to true.

      Only a service role can modify.

    • passwordoptionalstring

      The user's password.

    • phoneoptionalstring

      The user's phone.

    • phone_confirmoptionalboolean

      Confirms the user's phone number if set to true.

      Only a service role can modify.

    • user_metadataoptionalobject

      A custom data object to store the user's metadata. This maps to the auth.users.user_metadata column.

      Only a service role can modify.

      The user_metadata should be a JSON object that includes user-specific info, such as their first and last name.

      Note: When using the GoTrueAdminApi and wanting to modify a user's metadata, this attribute is used instead of UserAttributes data.

Notes

  • To confirm the user's email address or phone number, set email_confirm or phone_confirm to true. Both arguments default to false.

Examples

Create a new user with custom user metadata

const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' }
})

Auto-confirm the user's email

const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
email_confirm: true
})

Auto-confirm the user's phone number

const { data, error } = await supabase.auth.admin.createUser({
phone: '1234567890',
phone_confirm: true
})