aircloudbase
v1.0.0
Published
React library for AirCloudBase API
Maintainers
Readme
AirCloudBase
A React library for interacting with the AirCloudBase API, providing authentication, database, document, project, and storage functionalities.
Features
- Authentication: Sign up, sign in, and manage user sessions with automatic token refresh
- Database Operations: Create, read, update, and delete databases and collections
- Document Management: Work with documents in collections with full CRUD operations
- Project Management: Manage user projects
- Storage: Upload and manage files
- Realtime Updates: Subscribe to real-time data changes
- React Hooks: Easy-to-use hooks for integrating with React components
- Context Provider: Centralized state management for the entire application
Installation
npm install aircloudbaseQuick Start
1. Wrap your app with the AirCloudBaseProvider
import React from 'react';
import { AirCloudBaseProvider } from 'aircloudbase';
const App = () => {
const config = {
baseURL: 'https://your-aircloudbase-api.com',
apiKey: 'your-api-key'
};
return (
<AirCloudBaseProvider config={config}>
{/* Your app components */}
</AirCloudBaseProvider>
);
};
export default App;2. Use the provided hooks in your components
import React from 'react';
import { useAuth, useDatabase } from 'aircloudbase';
const MyComponent = () => {
const { user, signIn, signOut, isAuthenticated } = useAuth();
const { getDocuments } = useDatabase();
const handleSignIn = async () => {
await signIn('[email protected]', 'password');
};
return (
<div>
{isAuthenticated ? (
<div>
<p>Welcome, {user?.username}!</p>
<button onClick={signOut}>Sign Out</button>
</div>
) : (
<button onClick={handleSignIn}>Sign In</button>
)}
</div>
);
};
export default MyComponent;API Reference
Authentication
The authentication module provides methods for user management:
import { useAuth } from 'aircloudbase';
const { signUp, signIn, signOut, user, isAuthenticated } = useAuth();Database Operations
Work with databases and collections:
import { useDatabase } from 'aircloudbase';
const {
createDatabase,
getDatabases,
createCollection,
getCollections,
getDocuments,
addDocument
} = useDatabase();Document Management
Manage documents within collections:
import { useDocument } from 'aircloudbase';
const { getDocument, updateDocument, deleteDocument } = useDocument();Project Management
Manage user projects:
import { useProject } from 'aircloudbase';
const { getProjects, createProject } = useProject();Realtime Updates
Subscribe to real-time data changes:
import { useRealtime } from 'aircloudbase';
const { subscribeToCollection } = useRealtime();Configuration
The AirCloudBaseProvider requires a configuration object with:
baseURL: The base URL of your AirCloudBase APIapiKey: Your API key for authentication (optional depending on your API setup)
Building
To build the library for production:
npm run buildThis will create distribution files in the dist directory.
Development
To run the library in development mode with watch:
npm run devTesting
To run tests:
npm testLicense
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
