Authentication Methods
XyraPanel supports two primary authentication methods:- API Keys - For programmatic access and automation
- Session Cookies - For browser-based applications and web interfaces
API Key Authentication
API keys provide secure, long-lived authentication tokens for automated access to the XyraPanel API.Creating an API Key
API keys can be created through the XyraPanel web interface:- Navigate to Account Settings → API Keys
- Click Create API Key
- Set an expiration date (max 90 days, default 90 days)
- Copy your API key immediately - it will only be shown once
Using API Keys
API keys can be provided in two ways:Bearer Token (Recommended)
Custom Header
API Key Configuration
API keys are configured inserver/utils/auth.ts:
API Key Properties
- Length: 32 characters (default)
- Storage: Hashed in database using bcrypt
- Expiration: 90 days (default), configurable between 1-90 days
- Permissions: Inherits user permissions
- Revocation: Can be deleted at any time via the API or web interface
Security Best Practices
Session Cookie Authentication
Session cookies are automatically set when you log in through the web interface. These are ideal for browser-based applications.Session Configuration
Sessions are configured via Better Auth:Session Features
- Multi-Session: Up to 5 concurrent sessions per user
- Auto-Renewal: Sessions refresh automatically
- Secure Cookies: HttpOnly, Secure (in production), SameSite=Lax
- Session Management: View and revoke active sessions
Cookie Attributes
Authentication Headers
When using API keys or sessions, all authenticated requests should include:Authentication Errors
401 Unauthorized
- Missing or invalid API key
- Expired API key
- Missing or expired session
401 API Key Required
- Endpoint requires API key authentication specifically
- Session cookies are not accepted for this endpoint
Example: Complete API Request
Example: Creating a Server
Managing API Keys Programmatically
List Your API Keys
Delete an API Key
Environment Variables
Authentication is configured via environment variables:.env.example
The
BETTER_AUTH_SECRET must be at least 32 characters in production. Generate one using:Advanced: Admin API Key Permissions
Admin API keys can have granular permissions using Access Control Lists (ACL):servers.read- List and view serversservers.write- Create and update serversusers.read- View usersusers.write- Manage usersnodes.read- View nodesnodes.write- Manage nodes
requireAdminApiKeyPermission() middleware.