Auth Usage Guide

Universal Wallet Authentication - Usage Guide

🎯 Overview

The Universal Wallet Authentication system provides single sign-on (SSO) across your entire platform. Users connect their wallet ONCE and stay authenticated across all pages.

✨ Features

- ✅ Single Sign-On: Connect once, authenticated everywhere

`

🚀 Basic Usage

Simple Page (No auth required)

`html `

Protected Page (Auth required)

`html `

System Architect Only Page

`html `

Contractor Only Page

`html `

🎨 Custom Integration

With Callbacks

`javascript await window.authIntegration.init({ showUI: false, // Don't show default UI onAuthSuccess: (authInfo) => { // Show custom UI document.getElementById('userAddress').textContent = authInfo.shortAddress; document.getElementById('workTime').textContent = authInfo.workTimeMinutes + ' mins'; }, onAuthFail: () => { // Show login prompt } }); `

Manual Connection

`javascript // Connect wallet manually document.getElementById('myConnectBtn').addEventListener('click', async () => { try { const authInfo = await window.universalWalletAuth.connect(); } catch (error) { console.error('Connection failed:', error); } }); `

Check Auth Status

`javascript // Check if authenticated if (window.authIntegration.isAuthenticated()) { const authInfo = window.authIntegration.getAuthInfo(); } `

Disconnect

`javascript // Disconnect and clear session await window.authIntegration.disconnect(); `

📊 Time Tracking

Time tracking automatically starts for approved contractors:

- ✅ Tracks active time on platform

// Get contractor work time const workMinutes = window.universalWalletAuth.getWorkTime(); const hours = Math.floor(workMinutes / 60); const mins = workMinutes % 60; `

🔐 Session Management

Session Duration

Sessions are stored in localStorage: These actions reset the inactivity timer: // System Architect if (window.universalWalletAuth.isSystemArchitect()) { }

// Approved Contractor if (window.universalWalletAuth.isApprovedContractor()) { } `

Authorized Wallets

System Architect wallets (case-insensitive):

// Authentication success window.addEventListener('authSuccess', (event) => { // event.detail = { address, shortAddress, sessionToken, authenticated, workTimeMinutes } });

// Logout window.addEventListener('authLogout', () => { // Redirect or show login }); `

🛠️ Advanced Usage

Custom Session Timeout

`javascript // Set custom timeout (in milliseconds) window.universalWalletAuth.sessionTimeout = 2 60 60 * 1000; // 2 hours window.universalWalletAuth.inactivityTimeout = 15 60 1000; // 15 minutes `

Manual Session Validation

`javascript const session = window.universalWalletAuth.loadSession(); if (window.universalWalletAuth.isSessionValid(session)) { } else { } `

🔍 Debugging

Enable detailed logging:

`javascript // Check auth status ); ); ); , 'minutes'); `

📋 Example: Complete Integration

`html My Protected Page

🤖 AUL-enabled
`

🚨 Security Notes

1. Signature Verification: Every session requires cryptographic signature 2. No Transaction Risk: Signature does NOT authorize any blockchain transactions 3. Session Tokens: Generated from wallet address + signature + timestamp 4. Auto-Logout: Sessions expire after 4 hours or 30 minutes of inactivity 5. Wallet Changes: Auto-logout if user switches wallet or network

🎯 Best Practices

1. ✅ Always include scripts in correct order 2. ✅ Use requireAuth for protected pages 3. ✅ Handle authSuccess and authLogout events 4. ✅ Test session expiry flows 5. ✅ Provide clear UX for expired sessions 6. ✅ Show work time to contractors for transparency


← Back to Home