A comprehensive JavaScript module that provides Web3/OAuth authentication and universal genomic file import functionality for any web application using GenoBank.io's blockchain-based authentication system.
- 🛡️ Enhanced Error Handling: Custom error types with detailed debugging information
- 🌐 Multi-Network Support: Story, Avalanche, and Ethereum networks
- 🔧 Dependency Management: Automatic dependency loading and validation
- 🧩 Plugin System: Extensible architecture with analytics and custom plugins
- ⚛️ Framework Adapters: Native React and Vue 3 integration
- 🧪 Comprehensive Testing: Full test suite with 90%+ coverage
- 📦 Modern Build System: Rollup-based build with ES modules and UMD
- Dual Authentication: Support for both MetaMask wallet and Google OAuth login
- Universal Compatibility: Works with vanilla JavaScript, React, Vue, Angular, and any web framework
- Easy Integration: Simple API with pre-built UI components
- Configurable: Flexible configuration for different environments and networks
- Mobile-Friendly: Responsive authentication UI
- Multi-Blockchain: Support for Story, Avalanche, and Ethereum networks
- Customizable: Easy to style and customize UI components
- Robust: Advanced error handling and dependency management
- Extensible: Plugin system for custom functionality
- Universal File Import: Works with any GenoBank application
- S3 Integration: Direct access to GenoBank's S3 bucket via API
- Streaming Support: Efficient handling of large genomic files
- Progress Tracking: Real-time progress updates with cancellation support
- Retry Logic: Automatic retry for transient network errors
- Metadata Preservation: Maintains file ownership, biosample info, and checksums
- File Validation: Automatic genomic file type detection
- Performance Optimized: Chunk-based streaming with memory efficiency
npm install @genobank/login-enhanced
# or
yarn add @genobank/login-enhanced<!-- Required dependencies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/3.0.0-rc.5/web3.min.js"></script>
<script src="https://auth.magic.link/sdk"></script>
<script src="https://cdn.jsdelivr.net/npm/@magic-ext/oauth/dist/extension.js"></script>
<!-- GenoBank Auth Enhanced -->
<script src="https://unpkg.com/@genobank/login-enhanced@latest/dist/genobank-auth.js"></script><!DOCTYPE html>
<html>
<head>
<title>My App with GenoBank Auth</title>
<!-- Include dependencies (see installation section) -->
</head>
<body>
<div id="auth-container"></div>
<script>
// Initialize authentication
const auth = new GenobankAuth({
environment: 'test', // or 'production'
onLoginSuccess: (data) => {
console.log('Login successful:', data);
// Handle successful login
},
onLoginError: (error) => {
console.error('Login failed:', error);
}
});
// Initialize UI
const authUI = new GenobankAuthUI(auth, {
containerSelector: '#auth-container'
});
// Render the authentication interface
authUI.render();
</script>
</body>
</html>import { useState, useEffect } from 'react';
import GenobankAuth from '@genobank/auth';
function MyComponent() {
const [auth] = useState(() => new GenobankAuth({
environment: 'production',
onLoginSuccess: (data) => console.log('Logged in:', data)
}));
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
setIsLoggedIn(auth.isLoggedIn());
}, [auth]);
const handleMetamaskLogin = async () => {
try {
await auth.loginWithMetamask();
setIsLoggedIn(true);
} catch (error) {
console.error('Login failed:', error);
}
};
if (isLoggedIn) {
return (
<div>
<p>Welcome! Wallet: {auth.getUserWallet()}</p>
<button onClick={() => { auth.logout(); setIsLoggedIn(false); }}>
Logout
</button>
</div>
);
}
return (
<button onClick={handleMetamaskLogin}>
Connect MetaMask
</button>
);
}const auth = new GenobankAuth({
environment: 'test', // 'test' or 'production'
magicApiKey: 'your-key', // Optional: Custom Magic API key
messageToSign: 'Custom message', // Optional: Custom signature message
onLoginSuccess: (data) => {}, // Callback on successful login
onLoginError: (error) => {}, // Callback on login error
onLogout: () => {}, // Callback on logout
autoRedirect: true, // Auto-redirect after login
redirectUrl: '/dashboard' // Custom redirect URL
});loginWithMetamask()- Initiate MetaMask wallet loginloginWithGoogle()- Initiate Google OAuth loginlogout()- Log out current userisLoggedIn()- Check if user is authenticated
getUserWallet()- Get user's wallet addressgetUserSignature()- Get user's authentication signaturegetLoginMethod()- Get login method ('metamask' or 'magic')isCurrentUserPermittee()- Check if user has permittee status
signPersonalMessage(message)- Sign a custom messageconnectToContract(address, abi)- Connect to smart contract
shortWallet(wallet)- Get shortened wallet addressshortText(text, start, end)- Utility for shortening text
const authUI = new GenobankAuthUI(auth, {
containerSelector: '#auth-container', // Container element selector
showLogo: true, // Show GenoBank logo
customCSS: 'my-custom-styles', // Additional CSS styles
buttonText: {
metamask: 'Connect Wallet', // Custom MetaMask button text
google: 'Sign in with Google' // Custom Google button text
}
});render()- Render authentication interfacerenderModal()- Render as modal popupcloseModal()- Close modalrenderUserProfile(selector)- Render user profile widgetshowError(message)- Display error message
const auth = new GenobankAuth({ environment: 'production' });
const authUI = new GenobankAuthUI(auth);
// Open login modal
document.getElementById('login-btn').onclick = () => {
authUI.renderModal();
};const authUI = new GenobankAuthUI(auth, {
customCSS: `
.genobank-auth-btn {
background: linear-gradient(45deg, #667eea, #764ba2);
border: none;
color: white;
}
.genobank-auth-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
`
});// After successful login, show user profile
if (auth.isLoggedIn()) {
authUI.renderUserProfile('#user-profile-container');
}// Connect to a smart contract after authentication
if (auth.isLoggedIn()) {
const contract = await auth.connectToContract(
'0x1234...', // Contract address
contractABI // Contract ABI
);
// Call contract methods
const result = await contract.someMethod();
}- API:
https://api-test.genobank.io - Network: Avalanche Testnet (Fuji)
- Chain ID: 43113
- API:
https://genobank.app - Network: Avalanche Mainnet
- Chain ID: 43114
const auth = new GenobankAuth({
onLoginSuccess: (data) => {
// data contains: wallet, signature, isPermittee, userInfo (for OAuth)
console.log('User logged in:', data);
},
onLoginError: (error) => {
console.error('Login failed:', error.message);
},
onLogout: () => {
console.log('User logged out');
}
});- Chrome 60+
- Firefox 55+
- Safari 11+
- Edge 79+
- Ethers.js v5+ - Ethereum library
- Web3.js v3+ - Web3 interactions
- Magic SDK - OAuth authentication
- Magic OAuth Extension - OAuth functionality
These must be included in your project:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/3.0.0-rc.5/web3.min.js"></script>
<script src="https://auth.magic.link/sdk"></script>
<script src="https://cdn.jsdelivr.net/npm/@magic-ext/oauth/dist/extension.js"></script>- Store sensitive data (API keys, private keys) securely
- Use HTTPS in production environments
- Validate user permissions on the server side
- Implement proper session management
- Never expose private keys in client-side code
-
MetaMask not detected
- Ensure MetaMask is installed and enabled
- Check for conflicts with other wallet extensions
-
OAuth redirect issues
- Verify redirect URI configuration
- Ensure proper HTTPS setup in production
-
Network connection errors
- Check if using correct environment (test/production)
- Verify network connectivity to Avalanche RPC
// Enable debug logging
window.DEBUG_GENOBANK_AUTH = true;
const auth = new GenobankAuth({
environment: 'test'
});- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
- Documentation: https://docs.genobank.io
- Issues: https://github.com/Genobank/login/issues
- Email: support@genobank.io
GenoBank.io - Decentralized Genomic Data Platform