Skip to main content

🚀 TKI Auth Setup Guide

Complete step-by-step installation guide for TKI Auth on Linux systems.

📋 Prerequisites​

  • Linux system (Ubuntu 20.04+ recommended)
  • Root or sudo access
  • Internet connection
  • Basic terminal knowledge

🔧 Step 1: Install Node.js with NVM​

Install NVM (Node Version Manager)​

# Download and install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# In lieu of restarting the shell
. "$HOME/.nvm/nvm.sh"

Install Node.js​

# Download and install Node.js version 22
nvm install 22

# Verify the Node.js version
node -v
# Should print "v22.16.0"

nvm current
# Should print "v22.16.0"

# Verify npm version
npm -v
# Should print "10.9.2"
Alternative Installation

If you prefer system-wide installation without NVM:

# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

# Verify installation
node -v && npm -v

đŸ—„ī¸ Step 2: MongoDB Atlas Setup​

TKI Auth uses MongoDB Atlas (cloud database) for data storage. You don't need to install MongoDB locally.

Create MongoDB Atlas Account​

  1. Go to MongoDB Atlas
  2. Create a free account or sign in
  3. Create a new project (e.g., "TKI Auth")

Create Database Cluster​

  1. Click "Build a Database"
  2. Choose FREE tier (M0 Sandbox)
  3. Select your preferred region
  4. Name your cluster (e.g., "tki-auth-cluster")
  5. Click "Create Cluster"

Configure Database Access​

  1. Database User:

    • Go to "Database Access" in left sidebar
    • Click "Add New Database User"
    • Choose "Password" authentication
    • Username: tkiauth
    • Password: Generate secure password or create custom
    • Database User Privileges: "Read and write to any database"
    • Click "Add User"
  2. Network Access:

    • Go to "Network Access" in left sidebar
    • Click "Add IP Address"
    • Click "Allow Access from Anywhere" (or add your server's IP)
    • Click "Confirm"

Get Connection String​

  1. Go to "Database" in left sidebar
  2. Click "Connect" on your cluster
  3. Choose "Connect your application"
  4. Driver: Node.js, Version: 5.5 or later
  5. Copy the connection string (looks like):
    mongodb+srv://tkiauth:<password>@tki-auth-cluster.xxxxx.mongodb.net/?retryWrites=true&w=majority&appName=tki-auth-cluster
  6. Replace <password> with your actual database user password
Connection String Example

Your final connection string should look like:

mongodb+srv://tkiauth:YourSecurePassword123@tki-auth-cluster.abc123.mongodb.net/?retryWrites=true&w=majority&appName=tki-auth-cluster

đŸ“Ļ Step 3: Install TKI Auth​

Download TKI Auth​

Download the latest version from BuiltByBit.

  1. Go into your root folder of the VPS with:
cd /root/
  1. Place the downloaded File into the root folder

  2. Unzip the Folder

  3. Now start with installing the Dependencies.

info

You can place the folder of TKI Auth in a different Folder too. It doesnt have to be root

Install Dependencies​

# Navigate to TKI Auth directory
cd DIRECTORY

# Install npm dependencies
npm install

# Install PM2 for process management (optional but recommended)
npm install -g pm2
info

Replace "DIRECTORY" with the Directory of TKI Auth

âš™ī¸ Step 4: Configure TKI Auth​

The configuration file already exists in the Config folder. You just need to edit it with your settings.

Basic Configuration​

Edit Config/config.yml with your settings:

BasicSettings:
Token: "YOUR_DISCORD_BOT_TOKEN"
GuildID: "YOUR_DISCORD_SERVER_ID"
MongoURI: "mongodb+srv://tkiauth:YourPassword@tki-auth-cluster.abc123.mongodb.net/?retryWrites=true&w=majority&appName=tki-auth-cluster"
ShowStats: true

ApiSettings:
Port: 3090
APIKey: "your-secure-api-key-here"
Ratelimit:
Enabled: true
Max: 100
RequireHWID: true

Presence:
Status: "idle"
Activity:
Enabled: true
Type: "Competing"
Intervall: 5
Texts:
- "{total-products} - Total Products"
- "{total-user} - Total Members"

# Configure roles, logging, and other settings as needed...
Important Configuration Fields

Required fields you MUST configure:

  • Token: Your Discord bot token
  • GuildID: Your Discord server ID
  • MongoURI: Your MongoDB Atlas connection string
  • APIKey: Generate a secure API key (32+ characters)

🔐 Step 5: Discord Bot Setup​

Create Discord Application​

  1. Go to Discord Developer Portal
  2. Click "New Application"
  3. Name your application (e.g., "TKI Auth Bot")
  4. Go to "Bot" section
  5. Click "Add Bot"
  6. Copy the bot token
  7. Enable necessary intents:
    • Message Content Intent
    • Server Members Intent
    • Presence Intent

Invite Bot to Server​

  1. Go to "OAuth2" → "URL Generator"
  2. Select scopes: bot
  3. Select bot permissions:
    • Send Messages
    • Use Slash Commands
    • Manage Roles
    • Read Message History
    • Create Public Threads
  4. Copy the generated URL and invite bot to your server
tip

To be safe you can just give the bot Adminstrator permission.

Get Discord Server ID​

  1. Enable Developer Mode in Discord (User Settings → Advanced → Developer Mode)
  2. Right-click your server name
  3. Click "Copy Server ID"
  4. Use this ID in your config.yml as GuildID

🚀 Step 6: Start TKI Auth​

Test Run​

# Navigate to TKI Auth directory
cd /root/DIRECTORY

# Start TKI Auth in development mode
node .
info

Replace "DIRECTORY" with the Directory of TKI Auth

Check the console output for any errors. You should see:

  • MongoDB connection successful
  • Discord bot logged in
  • API server started on port 3090

Production Deployment with PM2​

# Start with PM2
pm2 start index.js --name "tki-auth"

# Save PM2 configuration
pm2 save

# Setup PM2 to start on boot
pm2 startup
# Follow the instructions provided by PM2

# Monitor the application
pm2 status
pm2 logs tki-auth

🔒 Step 7: Security & Firewall​

Configure Firewall​

# Install UFW if not installed
sudo apt install ufw

# Allow SSH (important!)
sudo ufw allow ssh

# Allow TKI Auth API port
sudo ufw allow 3090

# Enable firewall
sudo ufw enable

# Check status
sudo ufw status
# Install Nginx
sudo apt install nginx

# Install Certbot for Let's Encrypt
sudo apt install certbot python3-certbot-nginx

# Create Nginx configuration
sudo nano /etc/nginx/sites-available/tki-auth
server {
listen 80;
server_name your-domain.com;

location /api/ {
proxy_pass http://localhost:3090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# Enable site
sudo ln -s /etc/nginx/sites-available/tki-auth /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# Get SSL certificate
sudo certbot --nginx -d your-domain.com

đŸŽ¯ Step 8: Verification & Testing​

Test MongoDB Connection​

The connection will be tested automatically when TKI Auth starts. Check the logs:

# If using PM2
pm2 logs tki-auth

# If using systemd
sudo journalctl -u tki-auth -f

# Look for: "MongoDB connected successfully"

Test TKI Auth API​

# Test API endpoint
curl -X POST http://localhost:3090/api/license/auth \
-H "Content-Type: application/json" \
-H "Authorization: your-secure-api-key-here" \
-d '{
"data": {
"product": "TestProduct",
"version": "1.0.0",
"licensekey": "TEST-LICENSE-KEY",
"ip": "127.0.0.1",
"hwid": "test-hwid"
}
}'

Test Discord Bot​

  1. Go to your Discord server
  2. Try slash commands: /product list, /license create
  3. The bot should respond (even if no products/licenses exist yet)
  4. Check bot logs for any errors

📊 Step 9: Monitoring & Maintenance​

Setup Log Rotation​

# Create logrotate configuration
sudo nano /etc/logrotate.d/tki-auth
/opt/tki-auth/logs/*.log {
daily
missingok
rotate 30
compress
notifempty
create 644 tki-auth tki-auth
postrotate
systemctl reload tki-auth
endscript
}

Regular Maintenance Tasks​

# Create maintenance script
nano /opt/tki-auth/maintenance.sh
#!/bin/bash

# Backup configuration
DATE=$(date +%Y%m%d_%H%M%S)
cp /opt/tki-auth/config/config.yml "/opt/backups/config_$DATE.yml"

# Clean old logs
find /opt/tki-auth/logs -name "*.log" -mtime +7 -delete 2>/dev/null || true

# Update TKI Auth (if needed)
# cd /opt/tki-auth && git pull && npm install && pm2 restart tki-auth

echo "Maintenance completed at $(date)"
# Make script executable
chmod +x /opt/tki-auth/maintenance.sh

# Add to crontab for daily execution
crontab -e

# Add line:
# 0 2 * * * /opt/tki-auth/maintenance.sh >> /var/log/tki-auth-maintenance.log 2>&1

✅ Step 10: Post-Installation Checklist​

  • Node.js and npm installed and working (node -v, npm -v)
  • MongoDB Atlas cluster created and connection string obtained
  • TKI Auth downloaded and dependencies installed (npm install)
  • Configuration file config/config.yml properly edited
  • Discord bot created, invited to server, and bot token added to config
  • Discord server ID added to config as GuildID
  • TKI Auth service running and starting on boot
  • Firewall configured and API accessible on port 3090
  • SSL certificate installed (for production with domain)
  • API endpoint tested and working
  • Discord bot commands working in your server
  • Monitoring and logs set up

🆘 Troubleshooting​

Common Issues​

MongoDB Connection Failed:

# Check your connection string format
# Verify MongoDB Atlas network access (allow your IP)
# Check database user credentials
# Look at TKI Auth logs for detailed error
pm2 logs tki-auth

TKI Auth Won't Start:

# Check logs for detailed error
pm2 logs tki-auth

# Common issues:
# - Wrong Discord bot token
# - Invalid MongoDB connection string
# - Missing required config fields
# - Port 3090 already in use

# Check Node.js version
node -v

Discord Bot Not Responding:

# Verify bot token is correct
# Check Discord Developer Portal - bot should show online
# Verify bot permissions in Discord server
# Check if bot has required intents enabled
# Look for authentication errors in logs

API Requests Failing:

# Check if TKI Auth is running
pm2 status

# Check firewall settings
sudo ufw status

# Test local connection
curl http://localhost:3090/health

# Verify API key in requests matches config

MongoDB Atlas Issues:

# Common MongoDB Atlas problems:
# - IP not whitelisted (add 0.0.0.0/0 for testing)
# - Wrong password in connection string
# - Database user doesn't have proper permissions
# - Network connectivity issues

npm install / Canvas Compilation Failed (Windows):

This error occurs when native modules like canvas, node-gyp, or similar packages fail to compile on Windows systems.

Error Symptoms:

  • gyp ERR! find Python - Python not found or not working
  • canvas compilation failed
  • node-pre-gyp 404 errors for prebuilt binaries
  • EPERM: operation not permitted errors

Solution 1: Install Build Tools

# Install Visual Studio Build Tools
npm install --global windows-build-tools

# Or install Visual Studio Build Tools manually from:
# https://visualstudio.microsoft.com/downloads/

# Alternative: Install with chocolatey
choco install visualstudio2019buildtools

Solution 2: Fix Python Configuration

# Check if Python is installed
python --version

# If Python not found, install Python 3.6+ from python.org
# Make sure to check "Add Python to PATH" during installation

# Configure npm to use correct Python
npm config set python "C:\Python311\python.exe"
# (adjust path to your Python installation)

# Set MSBuild version
npm config set msvs_version 2019

Solution 3: Clean Installation

# Clear npm cache
npm cache clean --force

# Remove node_modules and package-lock.json
rmdir /s node_modules
del package-lock.json

# Try installing with legacy-peer-deps
npm install --legacy-peer-deps

# Or skip canvas compilation
npm install --ignore-scripts

Solution 4: Use Node.js LTS Version

# Canvas might not support the latest Node.js version
# Install Node.js 18 LTS instead of 22

# With nvm-windows:
nvm install 18.20.0
nvm use 18.20.0
npm install

# Or download from nodejs.org

Solution 5: Alternative Approach

# If canvas is causing issues, try installing without it
npm install --ignore-scripts

# Or use Docker for consistent environment
docker run -it node:18-alpine sh

Linux-Specific Canvas Issues:

# Install required system dependencies
sudo apt-get update
sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev

# For CentOS/RHEL
sudo yum groupinstall "Development Tools"
sudo yum install cairo-devel pango-devel libjpeg-turbo-devel giflib-devel

# Then try npm install again
npm install

Permission Issues (Windows):

# Run PowerShell/CMD as Administrator
# Or try:
npm install --no-optional

# Fix permission issues
npm cache clean --force
npm config set cache C:\npm-cache --global

🎉 Congratulations!​

Your TKI Auth system is now installed and ready to use!

Next Steps:

  1. Configure Role Settings
  2. Integrate with Your Application
  3. Join Our Discord Community

Remember:

  • Keep your MongoDB Atlas connection string secure
  • Regularly backup your configuration files
  • Monitor your system for optimal performance
  • Update TKI Auth regularly for security and features