Skip to main content
The Database manager provides methods for user signup and password management with Auth0 database connections.

Methods

Signup

Creates a new user using active authentication with a database connection.
func (d *Database) Signup(
    ctx context.Context,
    params database.SignupRequest,
    opts ...RequestOption,
) (*database.SignupResponse, error)
ctx
context.Context
required
The context for the request
params
database.SignupRequest
required
The signup parameters
opts
...RequestOption
Optional request options

SignupRequest

client_id
string
The client ID of your application (uses default if not provided)
email
string
required
The user’s email address
password
string
required
The user’s desired password
connection
string
required
The name of the database connection
username
string
The user’s username (only valid if the connection requires a username)
phone_number
string
The user’s phone number
given_name
string
The user’s given name(s)
family_name
string
The user’s family name(s)
name
string
The user’s full name
nickname
string
The user’s nickname
picture
string
A URI pointing to the user’s picture
user_metadata
*map[string]interface{}
User metadata object (max 10 properties, property names max 100 chars, values max 500 chars)
extra_parameters
map[string]string
Extra parameters to merge into the request body (will override existing values)

Example

import (
    "context"
    "github.com/auth0/go-auth0/v2/authentication/database"
)

params := database.SignupRequest{
    Connection: "Username-Password-Authentication",
    Email:      "[email protected]",
    Password:   "SecurePassword123!",
    Username:   "john.doe",
    GivenName:  "John",
    FamilyName: "Doe",
    UserMetadata: &map[string]interface{}{
        "plan": "premium",
    },
}

user, err := auth.Database.Signup(ctx, params)
if err != nil {
    log.Fatalf("Signup failed: %v", err)
}

fmt.Printf("User created with ID: %s\n", user.ID)

Response

id
string
The user’s ID
email
string
The user’s email address
email_verified
bool
Indicates whether the user has verified their email address
username
string
The user’s username (if applicable)
phone_number
string
The user’s phone number
given_name
string
The user’s given name(s)
family_name
string
The user’s family name(s)
name
string
The user’s full name
nickname
string
The user’s nickname
picture
string
A URI pointing to the user’s picture
user_metadata
*map[string]interface{}
User metadata associated with the user

ChangePassword

Sends a change password email to the user.
func (d *Database) ChangePassword(
    ctx context.Context,
    params database.ChangePasswordRequest,
    opts ...RequestOption,
) (string, error)
ctx
context.Context
required
The context for the request
params
database.ChangePasswordRequest
required
The change password parameters
opts
...RequestOption
Optional request options

ChangePasswordRequest

client_id
string
The client ID of your Auth0 Application (uses default if not provided)
email
string
required
The user’s email address
connection
string
required
The name of the database connection
organization
string
The organization ID of the organization associated with the user
extra_parameters
map[string]string
Extra parameters to merge into the request body (will override existing values)

Example

import (
    "context"
    "github.com/auth0/go-auth0/v2/authentication/database"
)

params := database.ChangePasswordRequest{
    Connection: "Username-Password-Authentication",
    Email:      "[email protected]",
}

response, err := auth.Database.ChangePassword(ctx, params)
if err != nil {
    log.Fatalf("Failed to send change password email: %v", err)
}

fmt.Println("Password change email sent:", response)

Response

Returns a string response from the API, typically confirming the email was sent.

Example: Complete Registration Flow

package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/auth0/go-auth0/v2/authentication"
    "github.com/auth0/go-auth0/v2/authentication/database"
)

func main() {
    ctx := context.Background()
    
    // Initialize the auth client
    auth, err := authentication.New(
        ctx,
        "your-domain.auth0.com",
        authentication.WithClientID("your-client-id"),
        authentication.WithClientSecret("your-client-secret"),
    )
    if err != nil {
        log.Fatal(err)
    }
    
    // Sign up a new user
    signupParams := database.SignupRequest{
        Connection: "Username-Password-Authentication",
        Email:      "[email protected]",
        Password:   "SecurePass123!",
        GivenName:  "Jane",
        FamilyName: "Smith",
        UserMetadata: &map[string]interface{}{
            "subscription": "free",
            "newsletter":   true,
        },
    }
    
    user, err := auth.Database.Signup(ctx, signupParams)
    if err != nil {
        log.Fatalf("Failed to create user: %v", err)
    }
    
    fmt.Printf("Successfully created user: %s (%s)\n", user.Email, user.ID)
}

Error Handling

user, err := auth.Database.Signup(ctx, params)
if err != nil {
    if aerr, ok := err.(*authentication.Error); ok {
        switch aerr.StatusCode {
        case 400:
            fmt.Println("Bad request:", aerr.Message)
        case 409:
            fmt.Println("User already exists")
        default:
            fmt.Printf("API error: %s\n", aerr.Message)
        }
    } else {
        log.Fatalf("Request failed: %v", err)
    }
}

See Also

Build docs developers (and LLMs) love