@hotosm/hanko-auth 0.5.2 → 0.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotosm/hanko-auth",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Web component for HOTOSM SSO authentication with Hanko and OSM integration",
5
5
  "type": "module",
6
6
  "main": "dist/hanko-auth.umd.js",
@@ -17,13 +17,6 @@
17
17
  "dist",
18
18
  "src"
19
19
  ],
20
- "scripts": {
21
- "dev": "vite",
22
- "build": "vite build",
23
- "watch": "vite build --watch",
24
- "preview": "vite preview",
25
- "prepublishOnly": "pnpm build"
26
- },
27
20
  "keywords": [
28
21
  "hotosm",
29
22
  "hanko",
@@ -51,5 +44,11 @@
51
44
  },
52
45
  "devDependencies": {
53
46
  "vite": "^5.0.0"
47
+ },
48
+ "scripts": {
49
+ "dev": "vite",
50
+ "build": "vite build",
51
+ "watch": "vite build --watch",
52
+ "preview": "vite preview"
54
53
  }
55
- }
54
+ }
@@ -274,7 +274,7 @@ export const styles = css`
274
274
 
275
275
  .login-link {
276
276
  color: var(--login-btn-text-color, white);
277
- font-size: var(--login-btn-text-size, var(--hot-font-size-medium));
277
+ font-size: var(--hot-font-size-small);
278
278
  border-radius: var(
279
279
  --login-btn-border-radius,
280
280
  var(--hot-border-radius-medium)
@@ -303,11 +303,11 @@ export const styles = css`
303
303
  border: none;
304
304
  }
305
305
  .login-link.filled.primary {
306
- background: var(--login-btn-bg-color, var(--hot-color-primary-1000));
306
+ background: var(--hot-color-gray-950);
307
307
  color: var(--login-btn-text-color, white);
308
308
  }
309
309
  .login-link.filled.primary:hover {
310
- background: var(--login-btn-hover-bg-color, var(--hot-color-primary-900));
310
+ background: var(--hot-color-primary-800);
311
311
  }
312
312
  .login-link.filled.neutral {
313
313
  background: var(--login-btn-bg-color, var(--hot-color-neutral-600));
@@ -330,8 +330,8 @@ export const styles = css`
330
330
  border: 1px solid;
331
331
  }
332
332
  .login-link.outline.primary {
333
- border-color: var(--login-btn-bg-color, var(--hot-color-primary-1000));
334
- color: var(--login-btn-text-color, var(--hot-color-primary-1000));
333
+ border-color: var(--login-btn-bg-color, var(--hot-color-primary-950));
334
+ color: var(--login-btn-text-color, var(--hot-color-primary-950));
335
335
  }
336
336
  .login-link.outline.primary:hover {
337
337
  background: var(--login-btn-hover-bg-color, var(--hot-color-primary-50));
@@ -357,7 +357,7 @@ export const styles = css`
357
357
  border: none;
358
358
  }
359
359
  .login-link.plain.primary {
360
- color: var(--login-btn-text-color, var(--hot-color-primary-1000));
360
+ color: var(--login-btn-text-color, var(--hot-color-primary-950));
361
361
  }
362
362
  .login-link.plain.primary:hover {
363
363
  background: var(--login-btn-hover-bg-color, var(--hot-color-primary-50));
package/src/hanko-auth.ts CHANGED
@@ -195,6 +195,8 @@ export class HankoAuth extends LitElement {
195
195
  private _lastSessionId: string | null = null;
196
196
  private _hanko: any = null;
197
197
  private _isPrimary = false; // Is this the primary instance?
198
+ private _sessionCheckFailures = 0;
199
+ private _sessionCheckBackoffTimer: ReturnType<typeof setTimeout> | null = null;
198
200
  private _hankoObserver: MutationObserver | null = null;
199
201
 
200
202
  // Hanko signup headline text across all supported languages (used for subtitle injection)
@@ -368,6 +370,8 @@ export class HankoAuth extends LitElement {
368
370
  private _handleVisibilityChange = () => {
369
371
  // Only primary instance should handle visibility changes to prevent race conditions
370
372
  if (!this._isPrimary) return;
373
+ // Don't re-check if a backoff retry is already scheduled
374
+ if (this._sessionCheckBackoffTimer) return;
371
375
 
372
376
  if (!document.hidden && !this.showProfile && !this.user) {
373
377
  // Page became visible, we're in header mode, and no user is logged in
@@ -380,6 +384,8 @@ export class HankoAuth extends LitElement {
380
384
  private _handleWindowFocus = () => {
381
385
  // Only primary instance should handle window focus to prevent race conditions
382
386
  if (!this._isPrimary) return;
387
+ // Don't re-check if a backoff retry is already scheduled
388
+ if (this._sessionCheckBackoffTimer) return;
383
389
 
384
390
  if (!this.showProfile && !this.user) {
385
391
  // Window focused, we're in header mode, and no user is logged in
@@ -549,6 +555,16 @@ export class HankoAuth extends LitElement {
549
555
  }
550
556
  }
551
557
 
558
+ private _scheduleSessionRetry() {
559
+ if (this._sessionCheckBackoffTimer) return; // already scheduled
560
+ const delay = Math.min(1000 * 2 ** this._sessionCheckFailures, 60000);
561
+ this.log(`Session check failed, retrying in ${delay / 1000}s (attempt ${this._sessionCheckFailures})`);
562
+ this._sessionCheckBackoffTimer = setTimeout(() => {
563
+ this._sessionCheckBackoffTimer = null;
564
+ this.checkSession();
565
+ }, delay);
566
+ }
567
+
552
568
  private async checkSession() {
553
569
  this.log("Checking for existing Hanko session...");
554
570
 
@@ -592,6 +608,7 @@ export class HankoAuth extends LitElement {
592
608
  return;
593
609
  }
594
610
 
611
+ this._sessionCheckFailures = 0; // reset backoff on success
595
612
  this.log("Valid Hanko session found via cookie");
596
613
  this.log("Session data:", sessionData);
597
614
 
@@ -710,12 +727,16 @@ export class HankoAuth extends LitElement {
710
727
  this.log("No valid session cookie found - user needs to login");
711
728
  }
712
729
  } catch (validateError) {
730
+ this._sessionCheckFailures++;
713
731
  this.log("Session validation failed:", validateError);
714
- this.log("No valid session - user needs to login");
732
+ this._scheduleSessionRetry();
733
+ return;
715
734
  }
716
735
  } catch (error) {
736
+ this._sessionCheckFailures++;
717
737
  this.log("Session check error:", error);
718
- this.log("No existing session - user needs to login");
738
+ this._scheduleSessionRetry();
739
+ return;
719
740
  } finally {
720
741
  // Broadcast state changes to other instances
721
742
  if (this._isPrimary) {