updated README.md
This commit is contained in:
parent
b22a1c973c
commit
ea191bfa60
47
README.md
47
README.md
@ -11,26 +11,27 @@ A simple, secure, and flexible licensing library built for Node.js, React, Next.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install license-lib
|
npm install license-lib
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Environment Setup
|
Environment Setup
|
||||||
Create a .env file at the root with your database and JWT configuration:
|
Create a .env file at the root with your database and JWT configuration:
|
||||||
|
|
||||||
env
|
env
|
||||||
JWT_SECRET=your_jwt_secret
|
```JWT_SECRET=your_jwt_secret
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_NAME=license_db
|
DB_NAME=license_db
|
||||||
DB_USER_ADMIN=license_admin
|
DB_USER_ADMIN=license_admin
|
||||||
DB_PASS_ADMIN=secure_admin_password
|
DB_PASS_ADMIN=secure_admin_password
|
||||||
DB_USER_READER=license_reader
|
DB_USER_READER=license_reader
|
||||||
DB_PASS_READER=secure_reader_password
|
DB_PASS_READER=secure_reader_password
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
⚙️ Database Setup
|
⚙️ Database Setup
|
||||||
Use the provided SQL script to set up your database:
|
Use the provided SQL script to set up your database:
|
||||||
|
|
||||||
sql
|
```sql
|
||||||
Copy code
|
|
||||||
CREATE DATABASE license_db;
|
CREATE DATABASE license_db;
|
||||||
|
|
||||||
USE license_db;
|
USE license_db;
|
||||||
@ -52,52 +53,58 @@ CREATE USER 'license_admin'@'%' IDENTIFIED BY 'secure_admin_password';
|
|||||||
GRANT SELECT, INSERT, UPDATE ON license_db.* TO 'license_admin'@'%';
|
GRANT SELECT, INSERT, UPDATE ON license_db.* TO 'license_admin'@'%';
|
||||||
|
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
|
```
|
||||||
|
|
||||||
📦 API Endpoints
|
📦 API Endpoints
|
||||||
|
|
||||||
Generate License
|
Generate License
|
||||||
|
|
||||||
POST /generate-license
|
POST /generate-license
|
||||||
|
|
||||||
Body:
|
Body:
|
||||||
|
|
||||||
json
|
```json
|
||||||
Copy code
|
|
||||||
{
|
{
|
||||||
"userId": "user123",
|
"userId": "user123",
|
||||||
"licenseType": "subscription",
|
"licenseType": "subscription",
|
||||||
"tier": "pro",
|
"tier": "pro",
|
||||||
"validUntil": "2024-12-31"
|
"validUntil": "2024-12-31"
|
||||||
}
|
}
|
||||||
|
```
|
||||||
Response:
|
Response:
|
||||||
|
|
||||||
json
|
```json
|
||||||
Copy code
|
Copy code
|
||||||
{
|
{
|
||||||
"licenseKey": "generated.jwt.token"
|
"licenseKey": "generated.jwt.token"
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Validate License
|
Validate License
|
||||||
|
|
||||||
POST /validate-license
|
POST /validate-license
|
||||||
|
|
||||||
Body:
|
Body:
|
||||||
|
|
||||||
json
|
```json
|
||||||
Copy code
|
Copy code
|
||||||
{
|
{
|
||||||
"userId": "user123",
|
"userId": "user123",
|
||||||
"licenseKey": "generated.jwt.token"
|
"licenseKey": "generated.jwt.token"
|
||||||
}
|
}
|
||||||
|
```
|
||||||
Response:
|
Response:
|
||||||
|
|
||||||
json
|
```json
|
||||||
Copy code
|
|
||||||
{
|
{
|
||||||
"valid": true
|
"valid": true
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
🎯 Client Integration
|
🎯 Client Integration
|
||||||
Import functions directly from the client module:
|
Import functions directly from the client module:
|
||||||
|
|
||||||
javascript
|
```javascript
|
||||||
Copy code
|
|
||||||
import { activateLicense, generateFingerprint } from './client';
|
import { activateLicense, generateFingerprint } from './client';
|
||||||
|
|
||||||
// Validate license
|
// Validate license
|
||||||
@ -105,11 +112,12 @@ const valid = await activateLicense(userId, licenseKey);
|
|||||||
|
|
||||||
// Device fingerprinting
|
// Device fingerprinting
|
||||||
const fingerprint = generateFingerprint();
|
const fingerprint = generateFingerprint();
|
||||||
|
```
|
||||||
|
|
||||||
⚛️ React Integration
|
⚛️ React Integration
|
||||||
Use the provided React hook and provider:
|
Use the provided React hook and provider:
|
||||||
|
|
||||||
jsx
|
```jsx
|
||||||
Copy code
|
|
||||||
import { LicenseProvider } from './react/LicenseProvider';
|
import { LicenseProvider } from './react/LicenseProvider';
|
||||||
import useLicense from './react/useLicense';
|
import useLicense from './react/useLicense';
|
||||||
|
|
||||||
@ -123,11 +131,12 @@ const YourApp = () => {
|
|||||||
const { isLicensed } = useLicense();
|
const { isLicensed } = useLicense();
|
||||||
return <div>{isLicensed ? 'Licensed!' : 'Not Licensed!'}</div>;
|
return <div>{isLicensed ? 'Licensed!' : 'Not Licensed!'}</div>;
|
||||||
};
|
};
|
||||||
|
```
|
||||||
|
|
||||||
▲ Next.js Integration
|
▲ Next.js Integration
|
||||||
Wrap your component easily:
|
Wrap your component easily:
|
||||||
|
|
||||||
jsx
|
```jsx
|
||||||
Copy code
|
|
||||||
import withLicense from './nextjs/withLicense';
|
import withLicense from './nextjs/withLicense';
|
||||||
|
|
||||||
const Page = ({ isLicensed }) => (
|
const Page = ({ isLicensed }) => (
|
||||||
@ -135,10 +144,4 @@ const Page = ({ isLicensed }) => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
export default withLicense(Page, { userId: 'user123', licenseKey: 'jwt.token' });
|
export default withLicense(Page, { userId: 'user123', licenseKey: 'jwt.token' });
|
||||||
📌 License
|
```
|
||||||
This project is licensed under MIT.
|
|
||||||
|
|
||||||
vbnet
|
|
||||||
Copy code
|
|
||||||
|
|
||||||
Your licensing library is now fully documented and ready for developers to integrate easily into their projects.
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user