@aio-chat/service v1.0.1-16
@aio-chat/service
This package provides the backend service for the @aio-chat/client
. It handles chat logic, user management, authentication, database interactions, and real-time communication via WebSockets.
Features
- Authentication: Supports Direct, Auth Endpoint, JWT, Proxy, and Custom authentication methods.
- Database: Works with SQLite, MySQL, and PostgreSQL. Includes migration utilities.
- Real-time: Uses Socket.IO for real-time message delivery.
- Customizability: Override default chat logic, user filtering, authentication, and connect to your existing database.
Installation
Install the service package:
npm install @aio-chat/service
Quick Start
Setup
- Create a file to start the service (e.g.,
server.js
). Import and start the service:
import { startService } from '@aio-chat/service'; startService(config) .then(() => console.log("Chat service started successfully.")) .catch((err) => console.error("Failed to start chat service:", err));
Add a start command to your
package.json
:"scripts": { "start:service": "node path/to/server.js" }
Configuration
Key configuration options include:
DB_TYPE
: Type of database (sqlite
,mysql
, orpostgres
).AUTH_MODE
: Authentication mode (direct
,auth-endpoint
,jwt
,proxy
, orcustom
).user_mapping
: Map user fields to your database schema.TOKEN_SECRET
,PROXY_SECRET
: Secrets for specific auth modes.
For a full list of configuration options, refer to the Configuration Documentation.
Authentication
@aio-chat/service supports multiple authentication methods:
- Direct: Quick prototyping with minimal setup.
- Auth Endpoint: Verifies users through a backend endpoint.
- JWT: Uses existing JWT authentication systems.
- Proxy: Routes all chat requests through an authenticated backend.
- Custom: Implements custom authentication logic.
For detailed instructions, refer to the Authentication Documentation.
Database
@aio-chat/service supports SQLite, MySQL, and PostgreSQL. It includes migration utilities to set up and manage the database schema.
- SQLite: Ideal for quick setups or local development.
- MySQL/PostgreSQL: Recommended for production environments.
For more details, refer to the Database Documentation.
Customization
@aio-chat/service is designed to be highly customizable:
- Override default chat logic, user filtering, authentication and connect it to your existing database.
For advanced use cases, refer to the Chat Service Documentation.
Best Practices
- Change Default Authentication Method: Avoid using the default authentication method (
direct
) in production. Choose an authentication method that best fits your application's needs, such asjwt
,proxy
, orcustom
. - Update Authentication Defaults: Replace default authentication values like
TOKEN_SECRET
andPROXY_SECRET
with secure, unique values to enhance security. - Migrations: Before running migrations on existing database make sure to check documentation on User Entity customization.
Troubleshooting
Common Issues
- Authentication Errors: Ensure secrets and token names match between your app and the @aio-chat/service.
- CORS Issues: Configure CORS on both your proxy endpoint and the @aio-chat/service.
- Database Errors: Verify your database configuration and run migrations.
For more help, check the GitHub repository or create a new issue.
Related Packages
- @aio-chat/client: The frontend web component package.
License
This project is licensed under the MIT License.
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago