A simple and lightweight client library for integrating Mona Gallery functionality into your web applications.
npm install mona-gallery-client<script src="https://cdn.jsdelivr.net/npm/mona-gallery-client@1.0.0/mona-client.js"></script>// If using modules
import MonaClient from 'mona-gallery-client';
// Create a new instance
const mona = new MonaClient();
// Optionally configure with custom options
const mona = new MonaClient({
baseUrl: 'https://custom-api-url.com' // Optional: defaults to https://api.mona.gallery
});// Request OTP
const requestResult = await mona.requestOTP('user@example.com');
// Verify OTP
const verifyResult = await mona.verifyOTP('user@example.com', '123456');
// The access token is automatically stored in the client instanceconst profile = await mona.getUserProfile();// Get community assets
const communityAssets = await mona.getCommunityAssets();
// Get user's assets
const userAssets = await mona.getUserAssets();// Manually set an access token
mona.setAccessToken('your-access-token');
// Get the current access token
const token = mona.getAccessToken();All methods return promises and can throw errors. It's recommended to use try-catch blocks:
try {
const profile = await mona.getUserProfile();
} catch (error) {
console.error('Error fetching profile:', error);
}try {
// Request OTP
await mona.requestOTP('user@example.com');
// After user receives OTP via email
const result = await mona.verifyOTP('user@example.com', '123456');
if (result.accessToken) {
// Get user profile
const profile = await mona.getUserProfile();
console.log('Logged in user:', profile);
// Get user's assets
const assets = await mona.getUserAssets();
console.log('User assets:', assets);
}
} catch (error) {
console.error('Error:', error);
}MIT License