Authentication
The MJ Bot dashboard uses NextAuth with the Discord provider for authentication. Users log in with their Discord account, and the dashboard uses their Discord identity to determine which servers they can manage.
Configure Discord OAuth2
Step 1: Open the Developer Portal
Go to the Discord Developer Portal and select your bot's application.
Step 2: Add a Redirect URL
Navigate to the OAuth2 section in the left sidebar. Under Redirects, add the following URL:
https://your-domain.com/api/auth/callback/discord
Replace your-domain.com with your actual domain. Click Save Changes.
The redirect URL must match exactly, including the protocol (https://) and path. A mismatch will cause Discord to reject the login attempt with an "Invalid OAuth2 redirect_uri" error.
Step 3: Copy Your Credentials
On the same OAuth2 page, locate and copy the following values:
- Client ID -- displayed at the top of the page
- Client Secret -- click Reset Secret if you do not have one, then copy it
Your Client Secret is shown only once when generated. Store it securely. If you lose it, you will need to reset it, which invalidates the old secret.
Set Environment Variables
Open the dashboard .env file and set the following variables:
DISCORD_CLIENT_ID=your-client-id-here
DISCORD_CLIENT_SECRET=your-client-secret-here
NEXTAUTH_SECRET=your-random-secret-here
Generating NEXTAUTH_SECRET
NEXTAUTH_SECRET is used to encrypt session tokens and must be a random string of at least 32 characters. Generate one with:
openssl rand -base64 32
Copy the output and paste it as the value for NEXTAUTH_SECRET.
Never share or commit your NEXTAUTH_SECRET or DISCORD_CLIENT_SECRET. If either is compromised, rotate them immediately.
Restart the Dashboard
Apply the changes by restarting the dashboard:
pm2 restart mj-dashboard
Test the Login
- Open your dashboard in a browser:
https://your-domain.com - Click the Login or Sign in with Discord button.
- You should be redirected to Discord's authorization page.
- After authorizing, you should be redirected back to the dashboard and logged in.
If the login redirects you to an error page, check the dashboard logs for details:
pm2 logs mj-dashboard --lines 50
Common issues include mismatched redirect URLs, incorrect client credentials, or a missing NEXTAUTH_SECRET. See Common Issues for more help.
Summary of Required Environment Variables
| Variable | Description |
|---|---|
DISCORD_CLIENT_ID | Your Discord application's Client ID |
DISCORD_CLIENT_SECRET | Your Discord application's Client Secret |
NEXTAUTH_SECRET | A random 32+ character string for session encryption |
NEXTAUTH_URL | Your dashboard's public URL (e.g., https://your-domain.com) |