@nebulr-group/bridge-svelte 1.0.0-alpha.6 → 1.0.0-alpha.8

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/bootstrap.js CHANGED
@@ -76,6 +76,14 @@ export function bridgeBootstrap(options = {}) {
76
76
  const { url } = event;
77
77
  // Matched as the router resolves the route: decoded, without a trailing slash.
78
78
  const path = normalizePath(url.pathname);
79
+ // A sign-in request in the address is taken once, then the same page is loaded without it, so the address the
80
+ // navigation ends on never shows it: while it is unspent, anyone holding it could sign in on it.
81
+ if (config.signInRequests && url.searchParams.has('request')) {
82
+ await client.request.use(url.searchParams.get('request') ?? '').catch(() => undefined);
83
+ const clean = new URL(url);
84
+ clean.searchParams.delete('request');
85
+ redirect(307, `${clean.pathname}${clean.search}${clean.hash}`);
86
+ }
79
87
  // An email link lands on the email-links address with its token in the fragment: on to its page.
80
88
  followLink(config, url);
81
89
  if (config.authBase !== '' && path === config.authBase)
@@ -27,5 +27,11 @@ export declare function takeEndedReason(): SignedOutReason | null;
27
27
  * issuer and storage. A new issuer or storage replaces it.
28
28
  */
29
29
  export declare function startClient(config: ResolvedConfig, extra?: Partial<BridgeOptions>): Bridge;
30
+ /**
31
+ * Removes `request` from the address bar and the history entry once read:
32
+ * while the request is unspent, anyone who reads it there could sign in on
33
+ * it as themselves and plant the result in this browser.
34
+ */
35
+ export declare function dropRequestFromAddress(): void;
30
36
  /** For tests: forget the client. */
31
37
  export declare function resetClient(): void;
@@ -67,8 +67,10 @@ export function startClient(config, extra) {
67
67
  });
68
68
  // A page that signs in for other apps' sign-in requests takes the request from its address, before any form.
69
69
  const request = config.signInRequests && typeof location !== 'undefined' ? new URLSearchParams(location.search).get('request') : null;
70
- if (request !== null)
70
+ if (request !== null) {
71
71
  void client.request.use(request).catch(() => undefined);
72
+ dropRequestFromAddress();
73
+ }
72
74
  client.on('signed-out', ({ reason }) => {
73
75
  if (reason === 'session-ended' || reason === 'access-removed')
74
76
  lastEnded = reason;
@@ -81,6 +83,20 @@ export function startClient(config, extra) {
81
83
  clientStore.set(client);
82
84
  return client;
83
85
  }
86
+ /**
87
+ * Removes `request` from the address bar and the history entry once read:
88
+ * while the request is unspent, anyone who reads it there could sign in on
89
+ * it as themselves and plant the result in this browser.
90
+ */
91
+ export function dropRequestFromAddress() {
92
+ if (typeof window === 'undefined')
93
+ return;
94
+ const url = new URL(window.location.href);
95
+ if (!url.searchParams.has('request'))
96
+ return;
97
+ url.searchParams.delete('request');
98
+ window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
99
+ }
84
100
  /** For tests: forget the client. */
85
101
  export function resetClient() {
86
102
  get(clientStore)?.destroy();
package/dist/core/i18n.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * the plugin's own keys, the app's `messages` from bridgeBootstrap, and a
4
4
  * component's own `messages` prop, in that order of precedence (last wins).
5
5
  */
6
- import { createTranslator, interpolate, isBridgeError, normalizeLocale, } from '@nebulr-group/bridge-auth-core';
6
+ import { createTranslator, interpolate, isBridgeError, normalizeLocale, waitMinutes, } from '@nebulr-group/bridge-auth-core';
7
7
  import { PLUGIN_EN, PLUGIN_LOCALES } from './messages.js';
8
8
  let appLocale;
9
9
  let appMessages = {};
@@ -52,8 +52,15 @@ export function errorMessage(error, t, fallback = 'error.generic') {
52
52
  return t('error.unavailable');
53
53
  case 'network':
54
54
  return t('error.network');
55
- case 'rate-limited':
56
- return t('error.rateLimited');
55
+ case 'rate-limited': {
56
+ // A locked account has no time to wait: the owner resets the password.
57
+ if (e.code === 'account_locked')
58
+ return t('login.error.accountLocked');
59
+ const minutes = e.code === 'too_many_attempts' ? waitMinutes(e) : null;
60
+ if (minutes === null)
61
+ return t('error.rateLimited');
62
+ return minutes === 1 ? t('login.error.tooManyAttemptsOneMinute') : t('login.error.tooManyAttempts', { minutes });
63
+ }
57
64
  case 'signed-out':
58
65
  case 'reauthenticate':
59
66
  return t('session.ended');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebulr-group/bridge-svelte",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "The Bridge for SvelteKit: sign-in in your own pages, workspaces, flag-based route guards, plans and checkout, the team panel and live updates, on one setting: the issuer.",
5
5
  "author": "Iman Pouya",
6
6
  "license": "MIT",
@@ -60,7 +60,7 @@
60
60
  "@sveltejs/kit": "^2.0.0"
61
61
  },
62
62
  "dependencies": {
63
- "@nebulr-group/bridge-auth-core": "1.0.0-alpha.6"
63
+ "@nebulr-group/bridge-auth-core": "1.0.0-alpha.8"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@sveltejs/kit": "^2.16.0",