web-manager 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/modules/utilities.js +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -354,6 +354,35 @@ unsubscribe();
|
|
|
354
354
|
Add these classes to elements for automatic auth functionality:
|
|
355
355
|
- `.auth-signout-btn` - Sign out button (shows confirmation dialog)
|
|
356
356
|
|
|
357
|
+
**⚠️ Auth State Timing**:
|
|
358
|
+
|
|
359
|
+
On fresh page loads, Firebase Auth needs time to restore the user session from IndexedDB/localStorage. Methods like `auth.isAuthenticated()`, `auth.getUser()`, and `auth.getIdToken()` may return `null`/`false` if called before auth state is determined.
|
|
360
|
+
|
|
361
|
+
**Problem:**
|
|
362
|
+
```javascript
|
|
363
|
+
// ❌ May fail on page load - auth state not yet determined
|
|
364
|
+
await Manager.dom().ready();
|
|
365
|
+
const token = await auth.getIdToken(); // Could throw if currentUser is null
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**Solution:** Use `auth.listen({ once: true })` to wait for auth state:
|
|
369
|
+
```javascript
|
|
370
|
+
// ✅ Wait for auth state to be determined first
|
|
371
|
+
auth.listen({ once: true }, async (result) => {
|
|
372
|
+
if (result.user) {
|
|
373
|
+
const token = await auth.getIdToken(); // Safe - user is authenticated
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
**When this matters:**
|
|
379
|
+
- Pages making authenticated API calls immediately on load
|
|
380
|
+
- OAuth callback pages
|
|
381
|
+
- Deep links requiring authentication
|
|
382
|
+
|
|
383
|
+
**When NOT needed:**
|
|
384
|
+
- User-triggered actions (button clicks) - auth state is always determined by then
|
|
385
|
+
|
|
357
386
|
### Data Binding System
|
|
358
387
|
|
|
359
388
|
Reactive DOM updates with `data-wm-bind` attributes:
|
|
@@ -81,8 +81,8 @@ class Utilities {
|
|
|
81
81
|
const timeout = options.timeout !== undefined ? options.timeout : 5000;
|
|
82
82
|
|
|
83
83
|
const $notification = document.createElement('div');
|
|
84
|
-
$notification.className = `alert alert-${type} alert-dismissible fade show position-fixed
|
|
85
|
-
$notification.style.
|
|
84
|
+
$notification.className = `alert alert-${type} alert-dismissible fade show position-fixed`;
|
|
85
|
+
$notification.style.cssText = 'z-index: 9999; top: 1rem; left: 50%; transform: translateX(-50%);';
|
|
86
86
|
$notification.innerHTML = `
|
|
87
87
|
${text}
|
|
88
88
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
@@ -137,22 +137,27 @@ class Utilities {
|
|
|
137
137
|
if (/edg/i.test(ua)) {
|
|
138
138
|
return 'edge';
|
|
139
139
|
}
|
|
140
|
+
|
|
140
141
|
// Opera before Chrome (Opera includes "Chrome" in UA)
|
|
141
142
|
if (/opera|opr/i.test(ua)) {
|
|
142
143
|
return 'opera';
|
|
143
144
|
}
|
|
145
|
+
|
|
144
146
|
// Brave before Chrome (Brave includes "Chrome" in UA)
|
|
145
147
|
if (navigator.brave || /brave/i.test(ua)) {
|
|
146
148
|
return 'brave';
|
|
147
149
|
}
|
|
150
|
+
|
|
148
151
|
// Chrome (including Chromium-based browsers)
|
|
149
152
|
if (/chrome|chromium|crios/i.test(ua)) {
|
|
150
153
|
return 'chrome';
|
|
151
154
|
}
|
|
155
|
+
|
|
152
156
|
// Firefox
|
|
153
157
|
if (/firefox|fxios/i.test(ua)) {
|
|
154
158
|
return 'firefox';
|
|
155
159
|
}
|
|
160
|
+
|
|
156
161
|
// Safari last (most browsers include "Safari" in UA)
|
|
157
162
|
if (/safari/i.test(ua)) {
|
|
158
163
|
return 'safari';
|
package/package.json
CHANGED