@authon/js 0.1.5 → 0.1.7

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/dist/index.js CHANGED
@@ -60,6 +60,7 @@ var DEFAULT_BRANDING = {
60
60
  borderRadius: 12,
61
61
  showEmailPassword: true,
62
62
  showDivider: true,
63
+ showSecuredBy: true,
63
64
  locale: "en"
64
65
  };
65
66
 
@@ -184,6 +185,7 @@ var ModalRenderer = class {
184
185
  ${emailForm}
185
186
  <p class="switch-view">${subtitle} <a href="#" id="switch-link">${subtitleLink}</a></p>
186
187
  ${footer}
188
+ ${b.showSecuredBy !== false ? `<div class="secured-by">Secured by <span class="secured-brand">Authon</span></div>` : ""}
187
189
  </div>
188
190
  `;
189
191
  }
@@ -280,6 +282,12 @@ var ModalRenderer = class {
280
282
  .footer { text-align: center; margin-top: 16px; font-size: 12px; color: var(--authon-dim); }
281
283
  .footer a { color: var(--authon-dim); text-decoration: none; }
282
284
  .footer a:hover { text-decoration: underline; }
285
+ .secured-by {
286
+ text-align: center; margin-top: 20px; padding-top: 16px;
287
+ border-top: 1px solid var(--authon-divider);
288
+ font-size: 11px; color: var(--authon-dim);
289
+ }
290
+ .secured-brand { font-weight: 600; color: var(--authon-muted); }
283
291
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
284
292
  @keyframes slideIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
285
293
  ${b.customCss || ""}
@@ -331,6 +339,7 @@ var ModalRenderer = class {
331
339
  // src/session.ts
332
340
  var SessionManager = class {
333
341
  accessToken = null;
342
+ refreshToken = null;
334
343
  user = null;
335
344
  refreshTimer = null;
336
345
  apiUrl;
@@ -347,11 +356,15 @@ var SessionManager = class {
347
356
  }
348
357
  setSession(tokens) {
349
358
  this.accessToken = tokens.accessToken;
359
+ this.refreshToken = tokens.refreshToken;
350
360
  this.user = tokens.user;
351
- this.scheduleRefresh(tokens.expiresIn);
361
+ if (tokens.expiresIn && tokens.expiresIn > 0) {
362
+ this.scheduleRefresh(tokens.expiresIn);
363
+ }
352
364
  }
353
365
  clearSession() {
354
366
  this.accessToken = null;
367
+ this.refreshToken = null;
355
368
  this.user = null;
356
369
  if (this.refreshTimer) {
357
370
  clearTimeout(this.refreshTimer);
@@ -360,10 +373,14 @@ var SessionManager = class {
360
373
  }
361
374
  scheduleRefresh(expiresIn) {
362
375
  if (this.refreshTimer) clearTimeout(this.refreshTimer);
363
- const refreshIn = Math.max((expiresIn - 60) * 1e3, 5e3);
376
+ const refreshIn = Math.max((expiresIn - 60) * 1e3, 3e4);
364
377
  this.refreshTimer = setTimeout(() => this.refresh(), refreshIn);
365
378
  }
366
379
  async refresh() {
380
+ if (!this.refreshToken) {
381
+ this.clearSession();
382
+ return null;
383
+ }
367
384
  try {
368
385
  const res = await fetch(`${this.apiUrl}/v1/auth/token/refresh`, {
369
386
  method: "POST",
@@ -371,7 +388,8 @@ var SessionManager = class {
371
388
  "Content-Type": "application/json",
372
389
  "x-api-key": this.publishableKey
373
390
  },
374
- credentials: "include"
391
+ credentials: "include",
392
+ body: JSON.stringify({ refreshToken: this.refreshToken })
375
393
  });
376
394
  if (!res.ok) {
377
395
  this.clearSession();
@@ -536,7 +554,10 @@ var Authon = class {
536
554
  const handler = async (e) => {
537
555
  if (e.data?.type === "authon-oauth-callback") {
538
556
  window.removeEventListener("message", handler);
539
- popup?.close();
557
+ try {
558
+ popup?.close();
559
+ } catch {
560
+ }
540
561
  try {
541
562
  const tokens = await this.apiPost("/v1/auth/oauth/callback", {
542
563
  code: e.data.code,
package/dist/index.mjs CHANGED
@@ -33,6 +33,7 @@ var DEFAULT_BRANDING = {
33
33
  borderRadius: 12,
34
34
  showEmailPassword: true,
35
35
  showDivider: true,
36
+ showSecuredBy: true,
36
37
  locale: "en"
37
38
  };
38
39
 
@@ -157,6 +158,7 @@ var ModalRenderer = class {
157
158
  ${emailForm}
158
159
  <p class="switch-view">${subtitle} <a href="#" id="switch-link">${subtitleLink}</a></p>
159
160
  ${footer}
161
+ ${b.showSecuredBy !== false ? `<div class="secured-by">Secured by <span class="secured-brand">Authon</span></div>` : ""}
160
162
  </div>
161
163
  `;
162
164
  }
@@ -253,6 +255,12 @@ var ModalRenderer = class {
253
255
  .footer { text-align: center; margin-top: 16px; font-size: 12px; color: var(--authon-dim); }
254
256
  .footer a { color: var(--authon-dim); text-decoration: none; }
255
257
  .footer a:hover { text-decoration: underline; }
258
+ .secured-by {
259
+ text-align: center; margin-top: 20px; padding-top: 16px;
260
+ border-top: 1px solid var(--authon-divider);
261
+ font-size: 11px; color: var(--authon-dim);
262
+ }
263
+ .secured-brand { font-weight: 600; color: var(--authon-muted); }
256
264
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
257
265
  @keyframes slideIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
258
266
  ${b.customCss || ""}
@@ -304,6 +312,7 @@ var ModalRenderer = class {
304
312
  // src/session.ts
305
313
  var SessionManager = class {
306
314
  accessToken = null;
315
+ refreshToken = null;
307
316
  user = null;
308
317
  refreshTimer = null;
309
318
  apiUrl;
@@ -320,11 +329,15 @@ var SessionManager = class {
320
329
  }
321
330
  setSession(tokens) {
322
331
  this.accessToken = tokens.accessToken;
332
+ this.refreshToken = tokens.refreshToken;
323
333
  this.user = tokens.user;
324
- this.scheduleRefresh(tokens.expiresIn);
334
+ if (tokens.expiresIn && tokens.expiresIn > 0) {
335
+ this.scheduleRefresh(tokens.expiresIn);
336
+ }
325
337
  }
326
338
  clearSession() {
327
339
  this.accessToken = null;
340
+ this.refreshToken = null;
328
341
  this.user = null;
329
342
  if (this.refreshTimer) {
330
343
  clearTimeout(this.refreshTimer);
@@ -333,10 +346,14 @@ var SessionManager = class {
333
346
  }
334
347
  scheduleRefresh(expiresIn) {
335
348
  if (this.refreshTimer) clearTimeout(this.refreshTimer);
336
- const refreshIn = Math.max((expiresIn - 60) * 1e3, 5e3);
349
+ const refreshIn = Math.max((expiresIn - 60) * 1e3, 3e4);
337
350
  this.refreshTimer = setTimeout(() => this.refresh(), refreshIn);
338
351
  }
339
352
  async refresh() {
353
+ if (!this.refreshToken) {
354
+ this.clearSession();
355
+ return null;
356
+ }
340
357
  try {
341
358
  const res = await fetch(`${this.apiUrl}/v1/auth/token/refresh`, {
342
359
  method: "POST",
@@ -344,7 +361,8 @@ var SessionManager = class {
344
361
  "Content-Type": "application/json",
345
362
  "x-api-key": this.publishableKey
346
363
  },
347
- credentials: "include"
364
+ credentials: "include",
365
+ body: JSON.stringify({ refreshToken: this.refreshToken })
348
366
  });
349
367
  if (!res.ok) {
350
368
  this.clearSession();
@@ -509,7 +527,10 @@ var Authon = class {
509
527
  const handler = async (e) => {
510
528
  if (e.data?.type === "authon-oauth-callback") {
511
529
  window.removeEventListener("message", handler);
512
- popup?.close();
530
+ try {
531
+ popup?.close();
532
+ } catch {
533
+ }
513
534
  try {
514
535
  const tokens = await this.apiPost("/v1/auth/oauth/callback", {
515
536
  code: e.data.code,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authon/js",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Authon core SDK — ShadowDOM login modal for any app",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",