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)
The context for the request
params
database.SignupRequest
required
The signup parameters
SignupRequest
The client ID of your application (uses default if not provided)
The user’s desired password
The name of the database connection
The user’s username (only valid if the connection requires a username)
The user’s family name(s)
A URI pointing to the user’s picture
User metadata object (max 10 properties, property names max 100 chars, values max 500 chars)
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
Indicates whether the user has verified their email address
The user’s username (if applicable)
The user’s family name(s)
A URI pointing to the user’s picture
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)
The context for the request
params
database.ChangePasswordRequest
required
The change password parameters
ChangePasswordRequest
The client ID of your Auth0 Application (uses default if not provided)
The name of the database connection
The organization ID of the organization associated with the user
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