Welcome, !
This content is only visible to authenticated users.
The Universal Authentication system provides single sign-on (SSO) across all pages of the BARBRICKDESIGN ecosystem. Once a user connects their wallet on the main index page and signs the verification message, they stay authenticated across ALL pages without reconnecting.
✅ Single Sign-On - Connect once, authenticated everywhere ✅ Signature-Based Auth - Uses signed message for verification ✅ 24-Hour Sessions - Auto-expires after 24 hours for security ✅ Cross-Page Persistence - localStorage-based, works across tabs ✅ Wallet Verification - Checks wallet is still connected ✅ Platform Agnostic - Works with Phantom, MetaMask, any wallet
---
`html
`- ✅ index.html - Main hub (sign-in page)
universal-dev-compensation.htmlinvestment-dashboard.htmlproject-status-dashboard.html---
`javascript
``javascript
const walletInfo = window.universalAuth.getWalletInfo();
if (walletInfo) {
// Full address
// Abbreviated
// 'Phantom' or 'MetaMask'
// Signed message
// Timestamp
}
`
`html
``javascript
// Auto-displays authentication status
window.universalAuth.displayAuthStatus('authStatus');
`
Output (if authenticated):
`
✅ Connected: ABC123...XYZ789 (Phantom)
`
Output (if not authenticated):
`
⚠️ Not connected [Connect Wallet link]
`
`javascript
// Redirect to index if not authenticated
window.addEventListener('DOMContentLoaded', async function() {
await window.universalAuth.checkAuth();
if (!window.universalAuth.requireAuth('/index.html')) {
// User will be redirected, this won't execute
return;
}
// User is authenticated, proceed with page logic
initializePage();
});
`
`javascript
// Get headers with wallet authentication
const headers = {
'Content-Type': 'application/json',
...window.universalAuth.getAuthHeaders()
};
// Headers will include: // 'X-Wallet-Address': '...' // 'X-Wallet-Type': 'Phantom' // 'X-Wallet-Signature': {...} // 'X-Verified-At': '2025-10-14T...'
fetch('/api/user-data', {
method: 'GET',
headers: headers
}).then(response => response.json())
.then(data => );
`
`javascript
// React to auth status changes
window.addEventListener('authStatusChanged', function(event) {
const walletInfo = event.detail;
if (walletInfo && walletInfo.isAuthenticated) {
updateUIForAuthenticatedUser(walletInfo);
} else {
updateUIForGuest();
}
});
`
`javascript
// Check if wallet hasn't changed
const isStillValid = await window.universalAuth.verifyCurrentWallet();
if (!isStillValid) {
alert('Your wallet connection has changed. Please reconnect.');
window.universalAuth.clearAuth();
window.location.href = '/';
}
`
---
`html
`---
`
User clicks "CONNECT WALLET"
↓
Wallet opens (Phantom/MetaMask)
↓
User approves connection
↓
Connection successful
↓
Sign verification message
↓
Signature stored in localStorage
↓
User is now authenticated
`
`
User clicks link to investment-dashboard.html
↓
Page loads universal-auth.js
↓
Auto-checks localStorage for wallet_verified
↓
Found! User still authenticated
↓
No reconnection needed
↓
Page shows authenticated content
`
`
User returns after 25 hours
↓
universal-auth checks timestamp
↓
Session expired
↓
clearAuth() called
↓
User redirected to index.html
↓
Must reconnect wallet
`
---
`javascript
'wallet_connected' // 'true' if connected
'wallet_address' // Full wallet address
'wallet_type' // 'Phantom' or 'MetaMask'
'wallet_balance' // Last known balance
'wallet_verified' // 'true' if signature collected
'wallet_signature' // JSON of signature
'wallet_verified_at' // ISO timestamp
`
---
✅ Signature Verification - Proves wallet ownership ✅ Time-Based Expiry - Sessions expire after 24 hours ✅ Wallet Address Check - Detects if user switched wallets ✅ No Passwords - Blockchain-native authentication ✅ Client-Side Only - No server dependencies
---
Check:
1. Is universal-auth.js loaded on the page?
2. Is it loaded BEFORE other wallet scripts?
3. Check console for errors
4. Verify localStorage has the keys above
Check:
1. Message signing happening in index.html
2. signVerificationMessage() function executing
3. No errors in console during signing
4. User not rejecting the signature request
Solution:
universal-auth.js:`javascript
// Change from 24 hours to 7 days
if (hoursSinceVerification < 168) { // 7 * 24 = 168
// ... authenticated
}
`---
`javascript
window.addEventListener('DOMContentLoaded', async function() {
await window.universalAuth.checkAuth(); // First thing!
// Then proceed with page logic
});
`
`javascript
if (!isAuth) {
alert('Please connect your wallet on the main page first!');
window.location.href = '/';
}
`
`javascript
setInterval(async () => {
const isValid = await window.universalAuth.verifyCurrentWallet();
if (!isValid) {
alert('Wallet changed! Please reconnect.');
window.universalAuth.clearAuth();
window.location.href = '/';
}
}, 30000); // Check every 30 seconds
`
`javascript
async function loadUserData() {
const wallet = window.universalAuth.getWalletInfo();
if (!wallet) return;
// Fetch user-specific data
const response = await fetch(/api/portfolio/${wallet.address}, {
headers: window.universalAuth.getAuthHeaders()
});
const data = await response.json();
displayData(data);
}
`
---
---
All pages now share authentication. No more reconnecting on every page!
Files:
universal-auth.js - Core authentication logicuniversal-wallet-connect.js - Wallet connectionindex.html - Sign-in pageNext: Test across all pages and push to GitHub!