Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Greens-Organization/pz-packs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The PZ Packs API uses Better Auth for authentication. API requests are authenticated using session-based cookies with Discord OAuth2 as the authentication provider.Authentication Flow
1. User Authentication
Users authenticate through the web application using Discord OAuth2:2. Session Cookie
Upon successful authentication, a session cookie is set:- Name:
better-auth.session_token - HTTP Only: Yes (not accessible via JavaScript)
- Secure: Yes (HTTPS only in production)
- SameSite: Set based on CORS configuration
- Max Age: 5 minutes (with refresh mechanism)
Better Auth implements session caching with a 5-minute cache duration to reduce database queries while maintaining security.
Making Authenticated Requests
Browser Requests
When making requests from a browser (same origin or with CORS credentials), cookies are automatically included:cURL Requests
For testing with cURL, include the session cookie:You can extract your session token from browser DevTools > Application > Cookies or by inspecting the Set-Cookie header after authentication.
Programmatic Access
For applications consuming the API, maintain the session cookie across requests:Session Management
Better Auth handles session lifecycle automatically:Session Creation
Sessions are created upon successful Discord OAuth authentication:Session Validation
The API validates sessions on protected endpoints using theauth macro:
- Extract session token from cookie
- Validate token against database/cache
- Load user data and role
- Check permissions if specified
Session Expiration
Sessions use cookie caching with automatic refresh:- Cache Duration: 5 minutes
- Refresh: Automatic on valid requests
- Expiration: Handled by Better Auth
Getting Current Session
Retrieve the current authenticated user:Logout
Invalidate the current session:Authorization and Permissions
Permission Checking
Protected endpoints specify required permissions:Role-Based Access
User Role:- Standard modpack operations (create, read, update, delete)
- Mod management within own modpacks
- Member management for own modpacks
- All user permissions
- Global mod updates (
mod:update-all) - Admin panel access (
admin:access)
Resource-Level Authorization
Beyond role permissions, controllers enforce resource-level rules: Modpack ownership:- Only owners can update or archive modpacks
- Only owners can manage members
- Owners and members can add/remove mods
Error Responses
401 Unauthorized
Returned when no valid session is found:- Missing session cookie
- Expired or invalid session token
- Session not found in database
403 Forbidden
Returned when authenticated but lacking permission:- User role lacks required permission
- Not the owner of the resource (for owner-only actions)
- Not a member of the modpack (for member actions)
CORS and Credentials
The API is configured to support cross-origin requests with credentials:Allowed Origins
Configure trusted origins in the environment:Security Considerations
Session Security
- HTTP-Only Cookies: Prevents XSS attacks
- Secure Flag: Ensures HTTPS-only transmission in production
- SameSite: Protects against CSRF attacks
- Database-Backed: Sessions stored in PostgreSQL with cache layer
Best Practices
- Never expose session tokens in client-side code or logs
- Use HTTPS in production to protect cookies in transit
- Implement CSRF protection if building forms that modify data
- Rotate secrets regularly for Discord OAuth credentials
- Monitor sessions for suspicious activity
Environment Variables
Required authentication configuration:Better Auth Endpoints
Better Auth provides these endpoints automatically:| Endpoint | Method | Description |
|---|---|---|
/auth/discord | GET | Initiate Discord OAuth flow |
/auth/discord/callback | GET | Handle OAuth callback |
/auth/session | GET | Get current session |
/auth/sign-out | POST | Sign out and clear session |
For a complete list of Better Auth endpoints, see the Better Auth documentation or the OpenAPI docs at
/docs in development mode.Testing Authentication
1. Authenticate via Browser
- Navigate to
http://localhost:3000/auth/discord - Complete Discord OAuth flow
- Open DevTools > Application > Cookies
- Copy the
better-auth.session_tokenvalue
2. Use Token in API Requests
3. Test Permission Levels
Next Steps
API Overview
Learn about API structure and response formats
Modpack Endpoints
Explore modpack API endpoints