From ccff136edb61de951ffdfbf7acfd867a80aa211f Mon Sep 17 00:00:00 2001
From: Your Name
Date: Sat, 20 Sep 2025 10:39:43 -0400
Subject: [PATCH] Single Source of Truth Architecture - Complete authentication
state management with storage-based getAuthState() as sole authoritative
source
---
.gitignore | 2 +-
README.md | 72 ++--
examples/button.html | 67 +++-
examples/embedded.html | 1 +
examples/login-and-profile.html | 30 +-
examples/modal.html | 1 +
examples/session-isolation-test.html | 534 +++++++++++++++++++++++++++
lite/build.js | 303 +++++++++++----
lite/nostr-lite.js | 305 +++++++++++----
login_logic.md | 413 +++++++++++++++++++++
themes/default/theme.css | 2 +-
11 files changed, 1530 insertions(+), 200 deletions(-)
create mode 100644 examples/session-isolation-test.html
create mode 100644 login_logic.md
diff --git a/.gitignore b/.gitignore
index 717048a..effd990 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
# Dependencies
node_modules/
-nostr-tools/
+
# IDE and OS files
.idea/
diff --git a/README.md b/README.md
index 03d730e..9b9ec8e 100644
--- a/README.md
+++ b/README.md
@@ -1,51 +1,47 @@
Nostr_Login_Lite
===========
-## Floating Tab API
+## API
-Configure persistent floating tab for login/logout:
+Configure for login/logout:
```javascript
-await NOSTR_LOGIN_LITE.init({
- // Set the initial theme (default: 'default')
- theme: 'dark', // Choose from 'default' or 'dark'
-
- // Standard configuration options
+await window.NOSTR_LOGIN_LITE.init({
+ theme: 'default',
+
methods: {
extension: true,
local: true,
+ seedphrase: true, // β Must be explicitly enabled
readonly: true,
connect: true,
- otp: true
+ otp: false
},
- // Floating tab configuration (now uses theme-aware text icons)
floatingTab: {
enabled: true,
- hPosition: 0.95, // 0.0-1.0 or '95%' from left
- vPosition: 0.5, // 0.0-1.0 or '50%' from top
- getUserInfo: true, // Fetch user profile name from relays
- getUserRelay: [ // Relays for profile queries
- 'wss://relay.damus.io',
- 'wss://nos.lol'
- ],
+ hPosition: 0.95, // Near right edge
+ vPosition: 0.1, // Near top
+
appearance: {
- style: 'pill', // 'pill', 'square', 'circle', 'minimal'
- theme: 'auto', // 'auto' follows main theme
- icon: '[LOGIN]', // Now uses text-based icons like [LOGIN], [KEY], [NET]
- text: 'Login'
+ style: 'pill',
+ icon: '[LOGIN]',
+ text: 'Sign In',
+ iconOnly: false
},
+
behavior: {
- hideWhenAuthenticated: false,
+ hideWhenAuthenticated: false, // Keep visible after login
showUserInfo: true,
autoSlide: true
},
- animation: {
- slideDirection: 'auto' // 'auto', 'left', 'right', 'up', 'down'
- }
+
+ getUserInfo: true, // β Fetch user profiles
+ getUserRelay: ['wss://relay.laantungir.net'] // Custom relays for profiles
}
});
+
// After initialization, you can switch themes dynamically:
NOSTR_LOGIN_LITE.switchTheme('dark');
NOSTR_LOGIN_LITE.switchTheme('default');
@@ -86,3 +82,31 @@ const modal = NOSTR_LOGIN_LITE.embed('#login-container', {
```
Container can be CSS selector or DOM element. Modal renders inline without backdrop overlay.
+
+## Logout API
+
+To log out users and clear authentication state:
+
+```javascript
+// Unified logout method - works for all authentication methods
+window.NOSTR_LOGIN_LITE.logout();
+```
+
+This will:
+- Clear persistent authentication data from localStorage
+- Dispatch `nlLogout` event for custom cleanup
+- Reset the authentication state across all components
+
+### Event Handling
+
+Listen for logout events in your application:
+
+```javascript
+window.addEventListener('nlLogout', () => {
+ console.log('User logged out');
+ // Clear your application's UI state
+ // Redirect to login page, etc.
+});
+```
+
+The logout system works consistently across all authentication methods (extension, local keys, NIP-46, etc.) and all UI components (floating tab, modal, embedded).
diff --git a/examples/button.html b/examples/button.html
index e0da565..d68664b 100644
--- a/examples/button.html
+++ b/examples/button.html
@@ -35,7 +35,7 @@
}
#login-button:hover {
- background: #0052a3;
+ opacity: 0.8;
}
@@ -49,6 +49,9 @@
+
+
π Session Isolation Test
+
+
+
π Test Instructions
+
+
Isolated Session: Each tab/window has independent authentication
+
Login in this tab/window - it will persist on refresh
+
Open new windows/tabs - they will start unauthenticated
+
Login with different users in different windows simultaneously
+
Refresh any window - authentication persists within that window only
+
+
+
+
+ π ISOLATED MODE (sessionStorage)
+
+
+
+ π¨ Session Isolation Active:
+
This tab uses sessionStorage - authentication is isolated to this window only. Refreshing will maintain your login state, but other tabs/windows are independent.