Authentication System

Secure authentication for development and production environments

DEVELOPMENT

Development Environment

CLI authentication server for local development

terminal
$ moonui dev# Starts auth server on :7878 + Next.js dev

CLI Auth Server

Runs on localhost:7878 for secure validation

Auto Project Start

Automatically starts your Next.js dev server

Framework Support

Use --no-nextjs for Vite/CRA

PRODUCTION

Production Environment

Automatic license validation during npm install

1

Set Environment Variable

MOONUI_LICENSE_KEY=moonui_xxx...# Add in Project Settings → Environment Variables
# Enable for: Production, Preview, Development
2

Configure Build System

Add token injection code to your framework config (see "Configure Build System" section below)

Next.js / Vite / CRA / Remix
3

Deploy Your App

During npm install, @moontra/moonui-pro automatically:

  • • Validates your license key with MoonUI API
  • • Saves a base64-encoded token to .moonui-license-token
  • • Token is read by next.config.ts and injected into app

Pro Features Unlocked! 🎉

All Pro components work automatically

Development Authentication

Enhanced CLI authentication server

The moonui dev Command

All-in-one development server with authentication

Default Usage (Next.js)

$ moonui dev# ✅ Starts CLI auth server on :7878
# ✅ Starts Next.js dev server on :3000
# ✅ Opens browser automatically

For Other Frameworks (Vite, CRA, etc.)

$ moonui dev --no-nextjs# ✅ Starts only CLI auth server on :7878
# ⚠️ You need to run your dev server separately

Auth Server Features

  • • Port: 7878
  • • Secure local validation
  • • 1 hour session cache
  • • Auto browser detection

Cache & Storage

  • • File: ~/.moonui/auth.encrypted
  • • Encrypted with device ID
  • • Auto-refresh on expiry
  • • Cross-project sharing

1. Setup Process

1

First-time login

$ moonui login

Opens browser for authentication

2

Start development

$ moonui dev

Starts auth server + project dev server

Ready to use Pro components!

Authentication handled automatically

Device Management

Free/Personal

1

device

Team

5

devices

Enterprise

unlimited

Provider Setup

Configure MoonUIAuthProvider in your application

Framework-Specific Setup

Add MoonUIAuthProvider to your application's root

app/layout.tsx

import { MoonUIAuthProvider } from '@moontra/moonui-pro'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <MoonUIAuthProvider>
          {children}
        </MoonUIAuthProvider>
      </body>
    </html>
  )
}

Production Authentication

Automatic PostInstall validation system

How PostInstall Works

Automatic license validation during package installation

1

npm install triggers PostInstall

When @moontra/moonui-pro is installed, the postinstall script runs automatically

2

License Validation

Script reads MOONUI_LICENSE_KEY and validates with MoonUI API

3

Token Storage

Base64-encoded token saved to .moonui-license-token in project root

4

Build Time Injection

Build system reads token file and injects it into your app bundle

Runtime Pro Access

MoonUIAuthProvider reads token and unlocks Pro components

Required Environment Variable:

MOONUI_LICENSE_KEY=moonui_xxx...# Get your license key from dashboard:
# https://moonui.dev/dashboard

Cache Strategy

Cache Durations

Development (CLI)
1 hour
Production (PostInstall)
30 days

Storage Locations

Development

~/.moonui/auth.encrypted

Production Build

.moonui-license-token

Runtime

App bundle (injected)
REQUIRED
Production Only

Configure Build System

Framework-specific configuration to inject license token at build time

Add to next.config.ts:

import type { NextConfig } from "next";
import { withMoonUIProToken } from '@moontra/moonui-pro/next-config';

const nextConfig: NextConfig = {
  // ... your other config
};

// Wrap your config with MoonUI Pro plugin
export default withMoonUIProToken(nextConfig);
Universal
v3.4.42+

Deploy Anywhere

The same two steps activate Pro on every platform — Vercel, self-hosted, or containers

PlatformWhere to set MOONUI_LICENSE_KEYNotes
VercelProject → Settings → Environment VariablesWorks out of the box
NetlifySite → Settings → Environment VariablesWorks out of the box
DockerARG / ENV in the Dockerfile (build arg)Add the prebuild script; keep build tools in dependencies
KubernetesIn the image build (CI), not a runtime env/SecretThe token is baked at build — a runtime Secret has no effect
Dokploy / NixpacksProject → Environment (build variables)Add the prebuild script
Bare server (PM2 / Node)Export in the build shell / CI before npm run buildSame prebuild script

Minimal Dockerfile (no VERCEL flag):

FROM node:22-slim
WORKDIR /app

COPY package*.json ./
# MOONUI_LICENSE_KEY as a build arg (kept out of the final image)
ARG MOONUI_LICENSE_KEY
ENV MOONUI_LICENSE_KEY=$MOONUI_LICENSE_KEY
ENV NODE_ENV=production

RUN npm install          # PostInstall validates the key + writes the token
COPY . .
RUN npm run build        # prebuild regenerates the token, withMoonUIProToken injects it
CMD ["npm", "start"]

Build with docker build --build-arg MOONUI_LICENSE_KEY=moonui_xxx -t my-app .

Troubleshooting

moonui dev not stopping with CTRL+C

If the dev server doesn't stop properly:

# Find and kill the process
$ lsof -i :7878
$ kill -9 [PID]

This issue has been fixed in v2.13.26+

Auth server not responding

Check if the auth server is running:

  1. 1. Verify port 7878 is not in use
  2. 2. Try moonui logout then moonui login
  3. 3. Clear auth cache: rm -rf ~/.moonui/auth.encrypted
  4. 4. Restart with moonui dev

PostInstall license validation failed

If Pro components remain locked in production:

  1. 1. Check Environment Variable
    • ✓ Verify MOONUI_LICENSE_KEY is set on your deployment platform
    • ✓ Confirm license key starts with moonui_
  2. 2. Check Build Logs
    • ✓ Look for [MoonUI Pro] PostInstall messages
    • ✓ Verify token file creation: ✓ Token saved to project root
  3. 3. Verify Package Version
    • ✓ Ensure @moontra/moonui-pro is version 3.4.42 or later
    • ⚠️ Self-hosted builds (Docker, Kubernetes, Dokploy, bare server) require 3.4.42+ — earlier versions only injected the token on Vercel/Netlify, leaving Pro silently locked elsewhere
    • ✓ Run npm update @moontra/moonui-pro@latest if needed
  4. 4. Check License Status

Token file not created during build

If PostInstall runs but token file isn't found:

If you see ❌ Error: Token file was not created, this indicates a file system permission issue on your deployment platform.

Clear all caches

To completely reset authentication:

# 1. Clear CLI auth
$ moonui logout
$ rm -rf ~/.moonui/auth.encrypted

# 2. Clear browser (in DevTools console)
localStorage.clear()
sessionStorage.clear()

# 3. Login again
$ moonui login
$ moonui dev