Members
User's email address - used for authentication and communication
# constant express
Social Media Dashboard API Server
Main Express.js server for the Social Media Dashboard API. Handles authentication, social media platform integrations, and provides RESTful endpoints for the frontend.
Features:
- JWT-based authentication
- OAuth integration with multiple social platforms
- Rate limiting and security middleware
- CORS configuration for frontend communication
- Swagger API documentation
- Version:
- 1.0.0
# constant jwt
Authentication Middleware
This module provides JWT-based authentication middleware for the Social Media Dashboard API. It handles token verification, user authentication, and token generation for secure API access.
- Version:
- 1.0.0
# last_login
Timestamp of user's last login for activity tracking
# constant mongoose
Database Configuration
This module handles MongoDB database connection for the Social Media Dashboard API. It provides a centralized way to connect to MongoDB with proper error handling and logging.
- Version:
- 1.0.0
# constant mongoose
User Model
Mongoose schema for user accounts in the Social Media Dashboard. Handles user authentication, profile information, and social media account associations.
- Version:
- 1.0.0
Object
# constant socialConfigs
Social Media Platform Configurations
Contains OAuth and API configuration for supported social media platforms:
- Instagram Business API
- TikTok for Business API
- YouTube Data API v3
- Facebook Graph API
- Snapchat Kit API
Each platform configuration includes:
- OAuth client credentials (from environment variables)
- Authorization and token URLs
- Required OAuth scopes
- API base URLs for data fetching
Properties:
| Name | Type | Description |
|---|---|---|
instagram |
Object
|
Instagram Business API configuration |
tiktok |
Object
|
TikTok for Business API configuration |
youtube |
Object
|
YouTube Data API v3 configuration |
facebook |
Object
|
Facebook Graph API configuration |
snapchat |
Object
|
Snapchat Kit API configuration |
mongoose.Schema
# constant userSchema
User Schema Definition
Defines the structure for user documents in MongoDB. Includes authentication fields, profile information, and social media account references.
Methods
# async authenticateToken(req, res, next) → {void}
Authenticate JWT Token Middleware
Verifies JWT tokens from the Authorization header and attaches the authenticated user to the request object. This middleware should be used on protected routes that require user authentication.
Parameters:
| Name | Type | Description |
|---|---|---|
req |
Object
|
Express request object |
res |
Object
|
Express response object |
next |
function
|
Express next middleware function |
Calls next() if authentication succeeds, sends error response if it fails
void
Example
// Protect a route
router.get('/protected', authenticateToken, (req, res) => {
// req.user is now available with the authenticated user
res.json({ user: req.user });
});
# async connectDB() → {Promise.<void>}
Connect to MongoDB Database
Establishes a connection to the MongoDB database using the URI from environment variables. Falls back to localhost if no MONGODB_URI is provided. Includes proper error handling and logging.
If connection fails, the process will exit with code 1
Error
Resolves when connection is established
Promise.<void>
Example
// In your main server file
const connectDB = require('./config/database');
connectDB().then(() => {
console.log('Server ready');
});
# generateRefreshToken(userId) → {string}
Generate JWT Refresh Token
Creates a new JWT refresh token for the specified user. Refresh tokens are used to obtain new access tokens without requiring the user to log in again. They have a longer expiration time.
Parameters:
| Name | Type | Description |
|---|---|---|
userId |
string
|
The MongoDB ObjectId of the user |
JWT refresh token
string
Example
const refreshToken = generateRefreshToken('507f1f77bcf86cd799439011');
// Returns: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# generateToken(userId) → {string}
Generate JWT Access Token
Creates a new JWT access token for the specified user. Access tokens are used for API authentication and have a shorter expiration time for security.
Parameters:
| Name | Type | Description |
|---|---|---|
userId |
string
|
The MongoDB ObjectId of the user |
JWT access token
string
Example
const token = generateToken('507f1f77bcf86cd799439011');
// Returns: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."