Licensor

Troubleshooting Guide

Solutions to common issues and errors when running WiLicensor Server.


Table of Contents


Database Issues

Database Connection Fails

Symptoms:

Solutions:

1. Verify PostgreSQL is running:

# Check if PostgreSQL is accepting connections
pg_isready -h your-host -p 5432

Expected output:

your-host:5432 - accepting connections

2. Test credentials:

# Try connecting directly
psql -h your-host -U your-user -d your-database

If connection fails, check:

3. Check SSL configuration:

For local development:

POSTGRES_SSL=false

For production (Heroku, Neon, etc.):

POSTGRES_SSL=true

4. Check environment variables:

# Windows (PowerShell)
$env:POSTGRES_HOST
$env:POSTGRES_USER
$env:POSTGRES_DATABASE

# Linux/Mac
echo $POSTGRES_HOST
echo $POSTGRES_USER
echo $POSTGRES_DATABASE

5. Check firewall:

6. Review logs:

# Application logs
npm run dev  # Look for error messages

# PostgreSQL logs (location varies by OS)
# Windows: C:\Program Files\PostgreSQL\15\data\log\
# Linux: /var/log/postgresql/

Table Does Not Exist

Symptoms:

Solutions:

1. Verify table exists:

psql -h your-host -U your-user -d your-database -c "\dt"

2. Restart application (creates tables automatically):

npm run dev

3. Check model definitions in models/ directory

4. Force sync (WARNING: Drops all tables):

// Temporary code in app.js
await sequelize.sync({ force: true });  // DANGER: Drops tables

Session Table Missing

Symptoms:

Solutions:

1. Check if table exists:

psql -h your-host -U your-user -d your-database -c "\dt session_pg"

2. Create table manually:

CREATE TABLE "session_pg" (
  "sid" varchar NOT NULL COLLATE "default",
  "sess" json NOT NULL,
  "expire" timestamp(6) NOT NULL
)
WITH (OIDS=FALSE);

ALTER TABLE "session_pg" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;

CREATE INDEX "IDX_session_expire" ON "session_pg" ("expire");

3. Enable auto-creation in sessions.js (should already be enabled):

store: new pgSession({
  pool: sequelize.connectionManager.pool,
  tableName: 'session_pg',
  createTableIfMissing: true  // Ensure this is true
})

Database Outage Handling

Symptoms:

Expected Behavior:

Verify Fallback:

# Should return fallback response even with invalid key
curl "http://localhost:5000/api/check?term=any_long_string_over_20_chars"

Expected response:

{
  "key": "any_long_string_over_20_chars",
  "condition": "activated",
  "type": "outage_fallback",
  "_outage_fallback": true,
  "_outage_fallback_expires": "2025-12-19T10:00:00.000Z"
}

Email Issues

Email Not Sending

Symptoms:

Solutions:

1. Test SMTP connection:

node test.js

Expected output:

Email sent: 250 2.0.0 OK ...

2. Verify Gmail App-Specific Password:

Problem: Using regular Gmail password instead of app-specific password

Solution:

  1. Enable 2-factor authentication on Gmail
  2. Generate App-Specific Password: https://support.google.com/accounts/answer/185833
  3. Use the 16-character password in EMAIL_PASSWORD

3. Check environment variables:

# Verify all email variables are set
echo $EMAIL_SENDER        # your-gmail@gmail.com
echo $EMAIL_PASSWORD      # app-specific password (16 chars)
echo $EMAIL_FROM_ALIAS    # Display name
echo $EMAIL_RECIPIENT     # Admin email

4. Verify Gmail settings:

5. Check SMTP configuration in mailer.js:

{
  host: 'smtp.gmail.com',
  port: 465,
  secure: true,  // SSL
  auth: {
    user: process.env.EMAIL_SENDER,
    pass: process.env.EMAIL_PASSWORD
  }
}

6. Test with different email:

Temporarily change EMAIL_SENDER to another Gmail account to isolate issue.


Emails Going to Spam

Symptoms:

Solutions:

1. Check SPF/DKIM records (if using custom domain):

2. Improve email content:

3. Use dedicated email service (for production):


Session Issues

Sessions Not Persisting

Symptoms:

Solutions:

1. Verify SESSION_SECRET is set:

echo $SESSION_SECRET

Should be 128+ characters. If not set:

npm run secret
# Copy output to .env.local

2. Check session_pg table exists:

psql -h your-host -U your-user -d your-database -c "SELECT COUNT(*) FROM session_pg;"

3. Verify cookie settings in sessions.js:

cookie: {
  maxAge: 30 * 24 * 60 * 60 * 1000,  // 30 days
  httpOnly: true,
  secure: process.env.NODE_ENV === 'production'  // false for dev
}

4. Check browser cookies:

5. For HTTPS sites, ensure secure: true:

cookie: {
  secure: true  // Only for HTTPS
}

"Invalid session secret"

Symptoms:

Solutions:

1. Generate new secret:

npm run secret

2. Add to .env.local:

SESSION_SECRET=your_128_character_hex_string

3. Restart application:

npm run dev

Webhook Issues

Webhooks Not Receiving Events

Symptoms:

Solutions:

1. Verify webhook URL in payment platform:

Stripe:

2. Check webhook signature:

Ensure STRIPE_WEBHOOK_SECRET matches value in Stripe dashboard.

3. Test locally with ngrok:

# Start ngrok
ngrok http 5000

# Use ngrok URL in Stripe
https://abc123.ngrok.io/webhook/stripe

# Test with Stripe CLI
stripe listen --forward-to localhost:5000/webhook/stripe
stripe trigger customer.subscription.created

4. Check webhook logs:

Stripe Dashboard → Webhooks → Click endpoint → Recent deliveries

Look for:

5. Verify webhook payload:

Add temporary logging in routes/webhook.js:

router.post('/webhook/stripe', async (req, res) => {
  console.log('Webhook received:', JSON.stringify(req.body, null, 2));
  // ... rest of code
});

6. Check signature verification:

If signature fails:


Keys Not Created from Webhook

Symptoms:

Solutions:

1. Check webhook logs:

# Application logs
npm run dev  # Look for error messages

2. Verify product exists:

If autoAdd setting is disabled, product must exist in database.

Enable autoAdd:

  1. Login to admin dashboard
  2. Go to Settings
  3. Enable "Auto Add Products"
  4. Save

3. Check metadata in Stripe:

Webhook expects:

{
  "metadata": {
    "productName": "Your Product Name",
    "quantity": "1"
  }
}

4. Verify email is sent:

Check admin email (EMAIL_RECIPIENT) for notification.


Authentication Issues

Cannot Login

Symptoms:

Solutions:

1. Verify email normalization:

Try logging in with:

2. Check user exists:

psql -h your-host -U your-user -d your-database -c "SELECT username, email FROM users;"

3. Reset password (admin access required):

  1. Login to admin dashboard
  2. Go to Manage Users
  3. Edit user
  4. Set new password

4. Check password hashing:

Passwords should be bcrypt hashed. If you see plain text passwords in database, model setter isn't working.


"Admin access required"

Symptoms:

Solutions:

1. Verify user role:

psql -h your-host -U your-user -d your-database -c "SELECT username, role FROM users;"

2. Update user role (if you have database access):

UPDATE users SET role = 'admin' WHERE email = 'your-email@example.com';

3. Create new admin user:

If no admin exists and ensureAdmin logic allows:

  1. Visit /register
  2. Create new user
  3. If no users exist, first user becomes admin

API Issues

API Returns 400 for Valid Key

Symptoms:

Solutions:

1. Check key format:

Ensure key matches encryption output:

curl "http://localhost:5000/keys/gen?term=YOUR_MACHINE_ID"

2. Verify key condition:

psql -h your-host -U your-user -d your-database -c "SELECT key, condition FROM keys WHERE key = 'YOUR_KEY';"

Key must have condition = 'activated' or 'ok' (not 'expired' or 'deactivated').

3. Check expiration:

psql -h your-host -U your-user -d your-database -c "SELECT key, \"endAt\" FROM keys WHERE key = 'YOUR_KEY';"

If endAt is in the past, key is expired.


API Returns 500 Error

Symptoms:

Solutions:

1. Check application logs:

npm run dev  # Look for stack traces

2. Enable verbose logging:

Add to route handler:

router.get('/api/check', async (req, res) => {
  try {
    console.log('Query params:', req.query);
    // ... rest of code
  } catch (error) {
    console.error('Full error:', error);
    // ...
  }
});

3. Check database connection:

500 errors often indicate database issues. Verify connection is active.


Deployment Issues

Vercel: "Module not found"

Symptoms:

Solutions:

1. Check package.json:

Ensure all dependencies are in dependencies, not devDependencies:

{
  "dependencies": {
    "express": "^4.17.1",
    "sequelize": "^6.37.1"
  }
}

2. Verify vercel.json configuration:

{
  "version": 2,
  "builds": [
    {
      "src": "app.js",
      "use": "@vercel/node"
    }
  ]
}

3. Check build logs in Vercel dashboard


Heroku: Database Connection Fails

Symptoms:

Solutions:

1. Verify DATABASE_URL is set:

heroku config:get DATABASE_URL

2. Check SSL configuration:

Heroku PostgreSQL requires SSL. Ensure in config/database.js:

dialectOptions: {
  ssl: {
    require: true,
    rejectUnauthorized: false
  }
}

3. Check Heroku logs:

heroku logs --tail

Docker: Container Exits Immediately

Symptoms:

Solutions:

1. Check container logs:

docker logs container_name

2. Run interactively:

docker run -it --env-file .env.local license-server sh

3. Verify environment variables:

docker run --env-file .env.local license-server printenv

4. Check database connectivity from container:

docker run -it --env-file .env.local license-server sh
# Inside container
apk add postgresql-client
psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DATABASE

Getting Help

Before Asking for Help

  1. Check application logs (npm run dev)
  2. Check database connection (psql or pg_isready)
  3. Test email (node test.js)
  4. Review environment variables
  5. Search this troubleshooting guide

Information to Include

When reporting issues, include:

  1. Error message (full stack trace)
  2. Environment:
    • OS (Windows, Linux, Mac)
    • Node.js version (node --version)
    • PostgreSQL version (psql --version)
  3. Configuration (sanitized):
    • .env.local (remove passwords)
    • Hosting platform (Vercel, Heroku, etc.)
  4. Steps to reproduce
  5. Expected vs. actual behavior
  6. Logs (application and database)

Support Channels



Last Updated: 2025-12-18