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[email protected]# 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[email protected])# 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.
# 1. User contacts you about forgotten password# 2. Reset password via CLItrail user change-password[email protected] 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[email protected] EmergencyP@ss123trail admin promote[email protected]# 3. Log in and create proper admin account via UI# 4. Delete emergency accounttrail user delete[email protected]
# users.csv format: email,password# [email protected],Password123# [email protected],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
# Check if user existssqlite3 traildepot/data/main.db "SELECT email FROM _user WHERE email = '[email protected]'"# 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 = '[email protected]'"# Delete existing user if appropriatetrail user delete[email protected]# Or modify existing user instead of creating new onetrail user change-password[email protected] 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;