@atlasauth/svelte 0.6.0 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @atlasauth/svelte changelog
2
2
 
3
+ ## 0.6.1
4
+ - **`<UserProfile>` can verify an address.** Each unverified email address now has a **Verify** button: it emails a code (`POST /v1/client/me/email_addresses/{id}/prepare_verification`) and shows a field to enter it (`attempt_verification`), then reloads the user. This includes the sign-up address on an app that does not require email verification, which now reads unverified until it is proven. New catalog keys: `userProfile.verify`, `userProfile.verifyConfirm`, `userProfile.verifyCodePlaceholder`, `userProfile.verifySendFailed`, `userProfile.verifyCodeRejected`.
5
+
3
6
  ## 0.6.0
4
7
  - **New `initAtlas({ onSignOut })` and `client.onSignOut(listener)`**: `onSignOut({ reason, sessionId })` fired once each time a signed-in user becomes signed out, on every
5
8
  path: `reason` is `user` (this tab), `other_tab`, `session_expired`, `revoked` (the session was ended elsewhere,
@@ -2,11 +2,50 @@
2
2
  import { getUser } from "../accessors";
3
3
  import { classFor } from "../appearance";
4
4
  import { translate } from "../i18n";
5
+ import { FapiClient } from "../fapi";
6
+ import { ATLAS_SVELTE_SDK } from "../version";
5
7
  const atlas = useAtlas();
6
8
  const user = getUser();
7
9
  const t = (key) => translate(atlas.catalog, key);
10
+ const client = new FapiClient({
11
+ publishableKey: atlas.publishableKey,
12
+ baseUrl: atlas.frontendApi,
13
+ locale: atlas.locale,
14
+ sdk: ATLAS_SVELTE_SDK
15
+ });
16
+ let verifying = null;
17
+ let code = "";
18
+ let busy = false;
19
+ let verifyError = null;
20
+ async function sendCode(id) {
21
+ verifyError = null;
22
+ busy = true;
23
+ const res = await client.post(`/v1/client/me/email_addresses/${id}/prepare_verification`);
24
+ busy = false;
25
+ if (!res.ok) {
26
+ verifyError = t("userProfile.verifySendFailed");
27
+ return;
28
+ }
29
+ code = "";
30
+ verifying = id;
31
+ }
32
+ async function confirmCode() {
33
+ if (!verifying) return;
34
+ verifyError = null;
35
+ busy = true;
36
+ const res = await client.post(`/v1/client/me/email_addresses/${verifying}/attempt_verification`, { code });
37
+ busy = false;
38
+ if (!res.ok) {
39
+ verifyError = t("userProfile.verifyCodeRejected");
40
+ return;
41
+ }
42
+ verifying = null;
43
+ await atlas.reload();
44
+ }
8
45
  $: current = $user.user;
9
46
  $: cardClass = classFor("card", atlas.appearance, "atlas-card");
47
+ $: inputClass = classFor("formFieldInput", atlas.appearance, "atlas-account-input");
48
+ $: buttonClass = classFor("formButtonSecondary", atlas.appearance, "atlas-button-secondary");
10
49
  </script>
11
50
 
12
51
  {#if current}
@@ -21,10 +60,31 @@ $: cardClass = classFor("card", atlas.appearance, "atlas-card");
21
60
  {email.email_address}
22
61
  {#if !email.verified}
23
62
  <em> — {t('userProfile.unverified')}</em>
63
+ {#if verifying === email.id}
64
+ <span data-atlas="email-verify">
65
+ <input
66
+ class={inputClass}
67
+ inputmode="numeric"
68
+ autocomplete="one-time-code"
69
+ placeholder={t('userProfile.verifyCodePlaceholder')}
70
+ bind:value={code}
71
+ />
72
+ <button class={buttonClass} type="button" disabled={busy} on:click={() => void confirmCode()}>
73
+ {t('userProfile.verifyConfirm')}
74
+ </button>
75
+ </span>
76
+ {:else}
77
+ <button class={buttonClass} type="button" disabled={busy} on:click={() => void sendCode(email.id)}>
78
+ {t('userProfile.verify')}
79
+ </button>
80
+ {/if}
24
81
  {/if}
25
82
  </li>
26
83
  {/each}
27
84
  </ul>
85
+ {#if verifyError}
86
+ <p role="alert">{verifyError}</p>
87
+ {/if}
28
88
  </section>
29
89
 
30
90
  <section>
package/dist/i18n.js CHANGED
@@ -79,6 +79,11 @@ export const EN_US = {
79
79
  'userProfile.addEmail': 'Add an email address',
80
80
  'userProfile.makePrimary': 'Make primary',
81
81
  'userProfile.unverified': 'Unverified',
82
+ 'userProfile.verify': 'Verify',
83
+ 'userProfile.verifyConfirm': 'Confirm',
84
+ 'userProfile.verifyCodePlaceholder': 'Code from the email',
85
+ 'userProfile.verifySendFailed': 'We could not send a code right now. Try again in a minute.',
86
+ 'userProfile.verifyCodeRejected': 'That code was not accepted.',
82
87
  'userProfile.revokeDevice': 'Sign out',
83
88
  'userProfile.deleteAccount': 'Delete account',
84
89
  'organization.switcher': 'Switch organization',
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { AtlasSdkInfo } from '@atlasauth/js';
2
2
  /** This package's version, sent as `X-Atlas-SDK` (kept in step with package.json by a test). */
3
- export declare const ATLAS_SVELTE_VERSION = "0.6.0";
3
+ export declare const ATLAS_SVELTE_VERSION = "0.6.1";
4
4
  export declare const ATLAS_SVELTE_SDK: AtlasSdkInfo;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** This package's version, sent as `X-Atlas-SDK` (kept in step with package.json by a test). */
2
- export const ATLAS_SVELTE_VERSION = '0.6.0';
2
+ export const ATLAS_SVELTE_VERSION = '0.6.1';
3
3
  export const ATLAS_SVELTE_SDK = { name: '@atlasauth/svelte', version: ATLAS_SVELTE_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlasauth/svelte",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "svelte": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "@atlasauth/design": "0.2.0",
26
26
  "@atlasauth/js": "0.12.0",
27
27
  "@atlasauth/authz": "0.1.1",
28
- "@atlasauth/backend": "0.8.0"
28
+ "@atlasauth/backend": "0.9.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "svelte": ">=4",