TrailBase provides comprehensive CLI commands for managing users and administrators. Unlike the admin UI, CLI commands allow you to modify admin users and perform operations that require elevated permissions.
trail user mint-token admin@example.com# Output:# Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1NTBlODQwMC1lMjliLTQxZDQtYTcxNi00NDY2NTU0NDAwMDAiLCJleHAiOjE3MDk4MjU0MTJ9.signature
The output is in Bearer token format and can be used directly in Authorization headers for API requests.
Use token with curl:
# Mint tokenTOKEN=$(trail user mint-token admin@example.com)# Use in API requestcurl -H "Authorization: ${TOKEN}" https://localhost:4000/api/records/v1/posts
Use cases:
Testing API endpoints
Automated scripts requiring authentication
Debugging authentication issues
Service-to-service authentication
Tokens are sensitive credentials. Handle them securely and never commit them to version control.
id email created updated550e8400-e29b-41d4-a716-446655440000 admin@example.com 2024-01-15T10:30:00Z 2024-03-07T14:22:00Z6ba7b810-9dad-11d1-80b4-00c04fd430c8 super@example.com 2024-02-01T08:15:00Z 2024-03-05T16:45:00Z
# 1. User contacts you about forgotten password# 2. Reset password via CLItrail user change-password user@example.com TemporaryP@ss123# 3. Send new temporary password to user via secure channel# 4. Instruct user to change password after login
# Scenario: Locked out of admin account# 1. Check if admin existstrail admin list# 2. If no admins exist, create emergency admintrail user add emergency@example.com EmergencyP@ss123trail admin promote emergency@example.com# 3. Log in and create proper admin account via UI# 4. Delete emergency accounttrail user delete emergency@example.com
# users.csv format: email,password# user1@example.com,Password123# user2@example.com,Password456# Create users from CSVwhile IFS=, read -r email password; do trail user add "$email" "$password"done < users.csv
Step-by-step: Verify all unverified users
# Get unverified user emails from databasesqlite3 traildepot/data/main.db \ "SELECT email FROM _user WHERE verified = 0" | \ while read -r email; do trail user verify "$email" true echo "Verified: $email" done
Error:Could not find user: user@example.comSolutions:
# Check if user existssqlite3 traildepot/data/main.db "SELECT email FROM _user WHERE email = 'user@example.com'"# List all userssqlite3 traildepot/data/main.db "SELECT email FROM _user"# Check by UUID insteadtrail user verify 550e8400-e29b-41d4-a716-446655440000 true
# Find existing usersqlite3 traildepot/data/main.db \ "SELECT id, email, verified FROM _user WHERE email = 'user@example.com'"# Delete existing user if appropriatetrail user delete user@example.com# Or modify existing user instead of creating new onetrail user change-password user@example.com NewP@ssw0rd
CREATE TABLE _user ( id BLOB PRIMARY KEY, -- UUID (16 bytes) email TEXT NOT NULL UNIQUE, -- Email address password_hash BLOB, -- Argon2id hash verified INTEGER NOT NULL, -- 0 = unverified, 1 = verified admin INTEGER NOT NULL, -- 0 = user, >0 = admin created INTEGER NOT NULL, -- Unix timestamp updated INTEGER NOT NULL -- Unix timestamp);CREATE INDEX idx_user_email ON _user(email);CREATE INDEX idx_user_admin ON _user(admin);
Query examples:
-- List all usersSELECT id, email, verified, admin, created FROM _user;-- Find unverified usersSELECT email FROM _user WHERE verified = 0;-- Count adminsSELECT COUNT(*) FROM _user WHERE admin > 0;-- Recent usersSELECT email, created FROM _user ORDER BY created DESC LIMIT 10;