9 KiB
Self-Hosted Database Setup Guide
This guide will show you how to set up your own authentication system and database for Monochrome accounts.
⚠️ Note: You will need to enter the same configurations on each device where you want to use your custom database.
Table of Contents
- Prerequisites
- Step 1: Setup Firebase Authentication
- Step 2: PocketBase Setup
- Step 3: Cloudflare Tunnel Setup
- Step 4: Getting Configurations
- Step 5: Linking with Monochrome
- Troubleshooting
Prerequisites
Before starting, ensure you have:
- A computer to host the database (can also use a VPS)
- A Firebase account (for authentication only)
- PocketBase installed on your host machine
- A domain name (free options available at DigitalPlat)
💡 This guide assumes you're setting everything up on your local machine. The process is identical for a VPS.
Step 1: Setup Firebase Authentication
1.1 Create a Firebase Project
- Go to the Firebase Console
- Create a new project
- On the left sidebar, click Build → Authentication
- Click Get Started
1.2 Enable Sign-in Methods
- Go to the Sign-in method tab
- Enable Google and Email providers
- Set your project support email
- Click Save
1.3 Authorize Your Domain
Firebase requires authorized domains for authentication:
- In Authentication → Settings → Authorized domains
- Click Add domain
- Add your hosting domain:
- If using the official Monochrome site:
monochrome.samidy.comor your preferred mirror (e.g.,monochrome.tf) - If self-hosting the website: add your custom domain
- If using the official Monochrome site:
💡
localhostis usually added by default for local testing. You can leave this enabled.
Step 2: PocketBase Setup
2.1 Install and Configure
- Download PocketBase and follow their setup guide
- Access the PocketBase Admin UI (typically at
http://127.0.0.1:8090/_/)
2.2 Create Collections
Create two collections: DB_users and public_playlists (do NOT use the default "users" collection)
DB_users Fields
| Field Name | Type | Description |
|---|---|---|
firebase_id |
Plain Text | Links to Firebase user ID |
lastUpdated |
Number | Timestamp of last update |
history |
JSON | User listening history |
library |
JSON | User's saved library |
user_playlists |
JSON | User's custom playlists |
user_folders |
JSON | User's playlist folders |
deleted_playlists |
JSON | Soft-deleted playlists |
username |
Plain Text | Unique username |
display_name |
Plain Text | Profile display name |
avatar_url |
URL | Profile avatar URL |
banner |
URL | Profile banner URL |
status |
Plain Text | User status |
about |
Plain Text | About me bio |
website |
URL | Personal website URL |
lastfm_username |
Plain Text | Last.fm username |
privacy |
JSON | Privacy settings |
profile_data_source |
Select (lastfm) | Preferred data source for profile |
favorite_albums |
JSON | User's favorite albums |
public_playlists Fields
| Field Name | Type | Description |
|---|---|---|
firebase_id |
Plain Text | Creator's Firebase user ID |
addedAt |
Number | Creation timestamp |
numberOfTracks |
Number | Total track count |
OriginalId |
Plain Text | Original playlist ID |
publishedAt |
Number | Publication timestamp |
title |
Plain Text | Playlist title |
uid |
Plain Text | Unique identifier |
uuid |
Plain Text | UUID for the playlist |
tracks |
JSON | Playlist tracks data |
image |
URL | Playlist cover image |
2.3 Configure API Rules
Set the API rules for both collections to allow read/write access:
DB_users API Rules:
- List/Search Rule:
firebase_id = @request.query.f_id || username != "" - View Rule:
firebase_id = @request.query.f_id || username != "" - Create Rule:
firebase_id = @request.query.f_id - Update Rule:
firebase_id = @request.query.f_id - Delete Rule:
firebase_id = @request.query.f_id
public_playlists API Rules:
- List/Search Rule:
uuid = @request.query.p_id - View Rule:
id != "" - Create Rule:
firebase_id = @request.query.f_id - Update Rule:
uid = @request.query.f_id - Delete Rule:
uid = @request.query.f_id
Step 3: Cloudflare Tunnel Setup
To make your PocketBase instance accessible from other devices securely:
3.1 Create a Cloudflare Account
- Sign up at the Cloudflare Dashboard
- Set up Zero Trust (free plan available)
3.2 Create a Tunnel
- In the Cloudflare dashboard, go to Zero Trust → Networks → Connectors
- Select Cloudflared
- Give your tunnel a name (e.g.,
monochrome-database) - Follow the installation guide for your operating system
3.3 Configure Hostname
- In the tunnel setup, add a Public Hostname
- Subdomain: Choose a subdomain (e.g.,
dbfordb.yourdomain.com) - Domain: Select your domain from the dropdown
- Service: Select HTTP
- URL: Enter your PocketBase local address (e.g.,
127.0.0.1:8090)
⚠️ Note: Cloudflare requires a valid domain. Free
.pages.devdomains won't work for this. Get a free domain at DigitalPlat.
- Save the configuration
Your database will now be accessible at your chosen domain!
Step 4: Getting Configurations
4.1 Get Firebase Configuration
- In the Firebase Console, open your project
- Click the ⚙️ Settings icon next to "Project Overview"
- Select Project settings
- In the General tab, scroll to "Your apps"
- Click the Web icon (
</>) - Register your app (e.g., "Monochrome Auth")
- Copy the
firebaseConfigobject:
const firebaseConfig = {
apiKey: 'AIzaSy...',
authDomain: 'your-project.firebaseapp.com',
databaseURL: 'https://your-project.firebaseio.com',
projectId: 'your-project',
storageBucket: 'your-project.appspot.com',
messagingSenderId: '...',
appId: '...',
};
⚠️ Copy only the object content inside the curly braces
{ ... }
4.2 Get Database URL
Simply copy your PocketBase domain from Cloudflare (e.g., https://db.yourdomain.com)
Step 5: Linking with Monochrome
Now configure Monochrome to use your custom backend:
- Open Monochrome in your browser
- Go to Settings (gear icon)
- Click ADVANCED: Custom Account Database
- Enter your configurations:
- Database Config: Your PocketBase domain (e.g.,
https://db.yourdomain.com) - Authentication Config: The Firebase config JSON object from Step 4.1
- Database Config: Your PocketBase domain (e.g.,
- Click Save
✅ Done! Your Monochrome instance is now connected to your custom database.
📝 Important: Repeat Step 5 on every device where you want to use your custom database.
Troubleshooting
Cannot sign in
- Ensure your domain is added to Firebase's authorized domains
- Check that the Firebase config JSON is correctly formatted
Database connection errors
- Verify your Cloudflare tunnel is running
- Check that PocketBase is accessible at your domain
- Ensure API rules are configured correctly
Data not syncing
- Make sure you're signed in with the same account on all devices
- Check the browser console for error messages
- Verify your database collections have the correct fields
Security Tips
- Keep your Firebase API key secure (it's okay to expose it for client-side auth, but don't share it unnecessarily)
- Regularly backup your PocketBase database
- Use strong, unique passwords for your Cloudflare and Firebase accounts
- Consider enabling 2FA on all accounts
Need Help?
- Join our Discord community (if available)
- Open an issue on GitHub
- Check existing GitHub issues for solutions