@hanzo/app 0.2.37 → 0.2.38
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/Accounts.d.ts +6 -0
- package/dist/Accounts.js +29 -0
- package/dist/Chrome.d.ts +7 -6
- package/dist/Chrome.js +12 -12
- package/dist/Orgs.js +4 -3
- package/dist/lib/accounts.d.ts +35 -0
- package/dist/lib/accounts.js +103 -0
- package/dist/lib/signout.js +9 -2
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Account } from './lib/accounts.js';
|
|
2
|
+
/** One account's face and words, the same wherever it is drawn. */
|
|
3
|
+
export declare function Face({ account }: {
|
|
4
|
+
account: Account;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export declare function Accounts(): import("react").JSX.Element;
|
package/dist/Accounts.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The accounts signed in on this browser, as a list: who they are, which one is
|
|
5
|
+
* this one, a tap to be another, and one to add. Log out is IAM's, and ends every
|
|
6
|
+
* one of them (lib/accounts), so it is said once, for all.
|
|
7
|
+
*/
|
|
8
|
+
import { Check, Plus } from 'lucide-react';
|
|
9
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
10
|
+
import { Text, View, XStack, YStack } from '@hanzo/gui';
|
|
11
|
+
import { Avatar, Button } from '@hanzo/ui';
|
|
12
|
+
import { label, useAccounts } from './lib/accounts.js';
|
|
13
|
+
import { useSignOut } from './lib/signout.js';
|
|
14
|
+
/** One account's face and words, the same wherever it is drawn. */
|
|
15
|
+
export function Face({ account }) {
|
|
16
|
+
const { title, line } = label(account);
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx(Avatar, { src: account.avatar || null, name: title, colorSeed: account.sub, alt: "" }), _jsxs(YStack, { flex: 1, minW: 0, gap: 2, children: [_jsx(Text, { fontSize: "$4", fontWeight: "500", color: "$ink", numberOfLines: 1, text: "start", children: title }), line ? (_jsx(Text, { fontSize: "$2", color: "$soft", numberOfLines: 1, text: "start", children: line })) : null] })] }));
|
|
18
|
+
}
|
|
19
|
+
export function Accounts() {
|
|
20
|
+
const { t } = useI18n();
|
|
21
|
+
const out = useSignOut();
|
|
22
|
+
const { accounts, current, switchTo, add } = useAccounts();
|
|
23
|
+
if (accounts.length === 0)
|
|
24
|
+
return null;
|
|
25
|
+
return (_jsxs(YStack, { render: "section", "aria-label": t('Accounts'), mt: 36, children: [_jsx(Text, { render: "h2", fontSize: "$6", fontWeight: "500", color: "$ink", children: t('Accounts') }), _jsx(YStack, { render: "ul", "aria-label": t('Signed in on this browser'), m: 0, p: 0, mt: 14, gap: 8, children: accounts.map((a) => {
|
|
26
|
+
const here = a.sub === current?.sub;
|
|
27
|
+
return (_jsx(View, { render: "li", display: "block", children: _jsxs(XStack, { render: "button", onClick: here ? undefined : () => void switchTo(a), "aria-current": here || undefined, width: "100%", items: "center", gap: 12, px: 12, py: 10, rounded: 12, borderWidth: 1, borderColor: here ? '$ink' : '$edge', bg: "transparent", cursor: here ? 'default' : 'pointer', hoverStyle: here ? undefined : { bg: '$hover' }, children: [_jsx(Face, { account: a }), here ? _jsx(Check, { size: 16, "aria-label": t('Current') }) : null] }) }, a.sub));
|
|
28
|
+
}) }), _jsxs(XStack, { mt: 14, gap: 8, flexWrap: "wrap", children: [_jsxs(Button, { type: "button", variant: "outline", onClick: () => void add(), children: [_jsx(Plus, { size: 16, "aria-hidden": true }), t('Add account')] }), _jsx(Button, { type: "button", variant: "ghost", onClick: () => void out(), children: t('Log out') })] })] }));
|
|
29
|
+
}
|
package/dist/Chrome.d.ts
CHANGED
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
* The brand at the start (`HanzoWordmark`: `brand()` in words, as the site's own bar sets it), going to this
|
|
6
6
|
* host's root; then the host's `back`, where the page has a step to go back to.
|
|
7
7
|
* At the end, once someone is signed in, who it is: the face, the name and the
|
|
8
|
-
* address,
|
|
9
|
-
* brand. Under gui's `md` the account folds into its face, a menu of the address
|
|
8
|
+
* address, the other accounts signed in on this browser to be one tap away
|
|
9
|
+
* (lib/accounts), Add account and Log out. Signed out, nothing but the brand. Under gui's `md` the account folds into its face, a menu of the address
|
|
10
10
|
* and the same two ways out.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* `rememberDestination`), so the sign-in that follows comes back
|
|
14
|
-
* hanzo.ai's /join does. Log out is the
|
|
15
|
-
* session is IAM's: the
|
|
12
|
+
* Being another account, and adding one, write this page down first
|
|
13
|
+
* (destination.ts `rememberDestination`), so the sign-in that follows comes back
|
|
14
|
+
* to it, as hanzo.ai's /join does, and neither ends a session. Log out is the
|
|
15
|
+
* account menu's own (lib/signout) and ends every one. The session is IAM's: the
|
|
16
|
+
* host mounts `IamProvider`.
|
|
16
17
|
*/
|
|
17
18
|
import { type ReactNode } from 'react';
|
|
18
19
|
export declare function Chrome({ back }: {
|
package/dist/Chrome.js
CHANGED
|
@@ -7,14 +7,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* The brand at the start (`HanzoWordmark`: `brand()` in words, as the site's own bar sets it), going to this
|
|
8
8
|
* host's root; then the host's `back`, where the page has a step to go back to.
|
|
9
9
|
* At the end, once someone is signed in, who it is: the face, the name and the
|
|
10
|
-
* address,
|
|
11
|
-
* brand. Under gui's `md` the account folds into its face, a menu of the address
|
|
10
|
+
* address, the other accounts signed in on this browser to be one tap away
|
|
11
|
+
* (lib/accounts), Add account and Log out. Signed out, nothing but the brand. Under gui's `md` the account folds into its face, a menu of the address
|
|
12
12
|
* and the same two ways out.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* `rememberDestination`), so the sign-in that follows comes back
|
|
16
|
-
* hanzo.ai's /join does. Log out is the
|
|
17
|
-
* session is IAM's: the
|
|
14
|
+
* Being another account, and adding one, write this page down first
|
|
15
|
+
* (destination.ts `rememberDestination`), so the sign-in that follows comes back
|
|
16
|
+
* to it, as hanzo.ai's /join does, and neither ends a session. Log out is the
|
|
17
|
+
* account menu's own (lib/signout) and ends every one. The session is IAM's: the
|
|
18
|
+
* host mounts `IamProvider`.
|
|
18
19
|
*/
|
|
19
20
|
import { useEffect, useState } from 'react';
|
|
20
21
|
import { useI18n } from '@hanzo/i18n/react';
|
|
@@ -22,7 +23,8 @@ import { useIam } from '@hanzo/iam/react';
|
|
|
22
23
|
import { Text, View, XStack, YStack } from '@hanzo/gui';
|
|
23
24
|
import { Avatar, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from '@hanzo/ui';
|
|
24
25
|
import { HanzoWordmark } from '@hanzogui/shell';
|
|
25
|
-
import {
|
|
26
|
+
import { Face } from './Accounts.js';
|
|
27
|
+
import { useAccounts } from './lib/accounts.js';
|
|
26
28
|
import { named } from './lib/session.js';
|
|
27
29
|
import { useSignOut } from './lib/signout.js';
|
|
28
30
|
import { brand, site } from './where.js';
|
|
@@ -57,16 +59,14 @@ export function Chrome({ back }) {
|
|
|
57
59
|
const email = u?.email || claimed?.email || '';
|
|
58
60
|
const avatar = typeof u?.avatar === 'string' && u.avatar.startsWith('https://') ? u.avatar : '';
|
|
59
61
|
const who = name || email;
|
|
60
|
-
const other = () => {
|
|
61
|
-
rememberDestination();
|
|
62
|
-
void signOut();
|
|
63
|
-
};
|
|
64
62
|
const out = () => void signOut();
|
|
63
|
+
const { accounts, current, switchTo, add } = useAccounts();
|
|
64
|
+
const others = accounts.filter((a) => a.sub !== current?.sub);
|
|
65
65
|
const signed = isAuthenticated && Boolean(who);
|
|
66
66
|
const moved = useMoved();
|
|
67
67
|
return (_jsxs(XStack, { render: "header", "data-slot": "masthead", "data-scrolled": moved ? 'true' : 'false', "data-tauri-drag-region": "deep", onMouseDown: dragWindow, onDoubleClick: toggleWindowMaximize, position: "sticky", t: 0, z: "var(--z-header)", shrink: 0, boxSizing: "content-box", height: HEIGHT, pt: NOTCH, px: 20, gap: 12, items: "center", bg: moved ? GLASS : 'transparent', backdropFilter: moved ? BLUR : 'none', transition: "quickest", borderBottomWidth: 0, children: [_jsx(Text, { render: _jsx("a", { href: "/", "aria-label": t('{brand} home', { brand: brand() }), "data-tauri-drag-region": "deep", onClick: (e) => {
|
|
68
68
|
if (typeof document !== 'undefined' && document.documentElement.getAttribute('data-desktop') === 'true') {
|
|
69
69
|
e.preventDefault();
|
|
70
70
|
}
|
|
71
|
-
} }), display: "flex", items: "center", shrink: 0, color: "var(--foreground)", textDecorationLine: "none", "data-tauri-drag-region": "deep", children: _jsx(HanzoWordmark, { label: brand(), size: 22, "data-tauri-drag-region": "deep" }) }), back, _jsx(View, { flex: 1, "data-tauri-drag-region": "deep" }), signed ? (_jsx(View, { render: "section", "aria-label": t('Account'), display: "flex", children: _jsxs(DropdownMenu, { placement: dir === 'rtl' ? 'bottom-start' : 'bottom-end', offset: 8, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(XStack, { render: "button", "aria-label": t('Account: {name}', { name: who }), width: 40, height: 40, rounded: 999, items: "center", justify: "center", borderWidth: 0, bg: "transparent", hoverStyle: { bg: '$hover' }, focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, cursor: "pointer", children: _jsx(Avatar, { src: avatar || null, name: who, alt: "" }) }) }), _jsxs(DropdownMenuContent, { minW: 240, maxW: "calc(100vw - 16px)", "aria-labelledby": undefined, "aria-label": t('Account'), children: [_jsx(DropdownMenuLabel, { children: _jsxs(YStack, { minW: 0, gap: 2, children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", numberOfLines: 1, children: who }), name && email ? (_jsx(Text, { fontSize: "$2", color: "$soft", numberOfLines: 1, children: email })) : null] }) }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onSelect: () => window.location.assign(site('/support')), children: _jsx(Text, { fontSize: "$3", color: "$ink", children: t('Help') }) }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onSelect:
|
|
71
|
+
} }), display: "flex", items: "center", shrink: 0, color: "var(--foreground)", textDecorationLine: "none", "data-tauri-drag-region": "deep", children: _jsx(HanzoWordmark, { label: brand(), size: 22, "data-tauri-drag-region": "deep" }) }), back, _jsx(View, { flex: 1, "data-tauri-drag-region": "deep" }), signed ? (_jsx(View, { render: "section", "aria-label": t('Account'), display: "flex", children: _jsxs(DropdownMenu, { placement: dir === 'rtl' ? 'bottom-start' : 'bottom-end', offset: 8, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(XStack, { render: "button", "aria-label": t('Account: {name}', { name: who }), width: 40, height: 40, rounded: 999, items: "center", justify: "center", borderWidth: 0, bg: "transparent", hoverStyle: { bg: '$hover' }, focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, cursor: "pointer", children: _jsx(Avatar, { src: avatar || null, name: who, alt: "" }) }) }), _jsxs(DropdownMenuContent, { minW: 240, maxW: "calc(100vw - 16px)", "aria-labelledby": undefined, "aria-label": t('Account'), children: [_jsx(DropdownMenuLabel, { children: _jsxs(YStack, { minW: 0, gap: 2, children: [_jsx(Text, { fontSize: "$3", fontWeight: "500", color: "$ink", numberOfLines: 1, children: who }), name && email ? (_jsx(Text, { fontSize: "$2", color: "$soft", numberOfLines: 1, children: email })) : null] }) }), _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuItem, { onSelect: () => window.location.assign(site('/support')), children: _jsx(Text, { fontSize: "$3", color: "$ink", children: t('Help') }) }), _jsx(DropdownMenuSeparator, {}), others.map((a) => (_jsx(DropdownMenuItem, { onSelect: () => void switchTo(a), children: _jsx(XStack, { items: "center", gap: 10, minW: 0, children: _jsx(Face, { account: a }) }) }, a.sub))), _jsx(DropdownMenuItem, { onSelect: () => void add(), children: _jsx(Text, { fontSize: "$3", color: "$ink", children: t('Add account') }) }), _jsx(DropdownMenuItem, { onSelect: out, children: _jsx(Text, { fontSize: "$3", color: "$ink", children: t('Log out') }) })] })] }) })) : null, _jsx(WindowControls, {})] }));
|
|
72
72
|
}
|
package/dist/Orgs.js
CHANGED
|
@@ -55,6 +55,7 @@ import { english } from './say.js';
|
|
|
55
55
|
import { countSignup } from './lib/intent.js';
|
|
56
56
|
import { BAD, mix } from './lib/mix.js';
|
|
57
57
|
import { useRooms } from './host.js';
|
|
58
|
+
import { Accounts } from './Accounts.js';
|
|
58
59
|
import { Chrome } from './Chrome.js';
|
|
59
60
|
import { site, where } from './where.js';
|
|
60
61
|
/** A template to set up once the organization is live. */
|
|
@@ -315,7 +316,7 @@ function Rule({ mt = 20, mb = 20 }) {
|
|
|
315
316
|
}
|
|
316
317
|
/** A screen's heading and the line under it; `lead` is the line's leading where it states one. */
|
|
317
318
|
function Heading({ title, lede, lead }) {
|
|
318
|
-
return (_jsxs(_Fragment, { children: [_jsx(Text, { render: "h1", fontSize: "$10", fontWeight: "500", letterSpacing: -0.32, color: "var(--text-primary)", children: title }), _jsx(Text, { render: "p", mt: 6, fontSize: "$4", lineHeight: lead, color: muted, children: lede })] }));
|
|
319
|
+
return (_jsxs(_Fragment, { children: [_jsx(Text, { render: "h1", fontSize: "$10", fontWeight: "500", letterSpacing: -0.32, color: "var(--text-primary)", children: title }), lede ? (_jsx(Text, { render: "p", mt: 6, fontSize: "$4", lineHeight: lead, color: muted, children: lede })) : null] }));
|
|
319
320
|
}
|
|
320
321
|
/** The room, held back until the organization is known. */
|
|
321
322
|
function Veil() {
|
|
@@ -603,11 +604,11 @@ function Pick({ members, current, onPick, onClose, }) {
|
|
|
603
604
|
document.addEventListener('keydown', key);
|
|
604
605
|
return () => document.removeEventListener('keydown', key);
|
|
605
606
|
}, [onClose, founding]);
|
|
606
|
-
return (_jsxs(Page, { label: t('Choose an organization'), children: [_jsxs(Column, { children: [_jsxs(XStack, { items: "flex-start", justify: "space-between", gap: 12, children: [_jsx(YStack, { flex: 1, minW: 0, children: _jsx(Heading, { title: t('Choose an organization')
|
|
607
|
+
return (_jsxs(Page, { label: t('Choose an organization'), children: [_jsxs(Column, { children: [_jsxs(XStack, { items: "flex-start", justify: "space-between", gap: 12, children: [_jsx(YStack, { flex: 1, minW: 0, children: _jsx(Heading, { title: t('Choose an organization') }) }), onClose ? (_jsx(Button, { variant: "ghost", size: "icon-sm", marginInlineEnd: -8, onClick: onClose, "aria-label": t('Close'), children: _jsx(X, { size: 16, "aria-hidden": true }) })) : null] }), _jsx(Rule, {}), _jsx(XStack, { render: "form", onSubmit: (e) => {
|
|
607
608
|
e.preventDefault();
|
|
608
609
|
if (shown[0])
|
|
609
610
|
onPick(shown[0].name);
|
|
610
|
-
}, children: _jsx(SearchInput, { name: "organizations", value: q, onChange: setQ, placeholder: t(sudo ? 'Search every organization' : 'Find an organization'), actions: sudo ? null : (_jsxs(Button, { type: "button", onClick: () => setFounding(true), children: [_jsx(Plus, { size: 16, "aria-hidden": true }), t('New organization')] })) }) }), _jsx(YStack, { render: "ul", "aria-label": t('Your organizations'), m: 0, p: 0, mt: 14, gap: 8, children: shown.map((o) => (_jsx(Choice, { org: o, current: o.name === current, onPress: () => onPick(o.name) }, o.name))) }), shown.length === 0 ? (_jsx(Text, { render: "p", mt: 14, fontSize: "$3", color: "$soft", children: t('None of yours matches “{query}”.', { query: q.trim() }) })) : null, sudo ? _jsx(Everyone, { q: q, skip: members }) : null] }), founding ? _jsx(Found, { onClose: () => setFounding(false) }) : null] }));
|
|
611
|
+
}, children: _jsx(SearchInput, { name: "organizations", value: q, onChange: setQ, placeholder: t(sudo ? 'Search every organization' : 'Find an organization'), actions: sudo ? null : (_jsxs(Button, { type: "button", onClick: () => setFounding(true), children: [_jsx(Plus, { size: 16, "aria-hidden": true }), t('New organization')] })) }) }), _jsx(YStack, { render: "ul", "aria-label": t('Your organizations'), m: 0, p: 0, mt: 14, gap: 8, children: shown.map((o) => (_jsx(Choice, { org: o, current: o.name === current, onPress: () => onPick(o.name) }, o.name))) }), shown.length === 0 ? (_jsx(Text, { render: "p", mt: 14, fontSize: "$3", color: "$soft", children: t('None of yours matches “{query}”.', { query: q.trim() }) })) : null, sudo ? _jsx(Everyone, { q: q, skip: members }) : null, _jsx(Accounts, {})] }), founding ? _jsx(Found, { onClose: () => setFounding(false) }) : null] }));
|
|
611
612
|
}
|
|
612
613
|
/**
|
|
613
614
|
* EVERY ORGANIZATION, for a SuperAdmin to step into.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** One person signed in on this browser: enough to recognise them, and to name them in a `login_hint`. */
|
|
2
|
+
export interface Account {
|
|
3
|
+
sub: string;
|
|
4
|
+
owner: string;
|
|
5
|
+
name: string;
|
|
6
|
+
displayName: string;
|
|
7
|
+
email: string;
|
|
8
|
+
avatar: string;
|
|
9
|
+
}
|
|
10
|
+
/** The accounts IAM holds for this browser, read from `base`. An answer that is not a list, or none, is nobody. */
|
|
11
|
+
export declare function read(base: string, signal?: AbortSignal): Promise<Account[]>;
|
|
12
|
+
/** What the page knows of the reader, to tell which account is theirs. */
|
|
13
|
+
export interface Who {
|
|
14
|
+
email?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
sub?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Whether `account` is the reader: the same subject, else the same address, else the same username. */
|
|
19
|
+
export declare function is(account: Account, who: Who): boolean;
|
|
20
|
+
/** The line a row says: the display name, else the username; and the address when it adds something. */
|
|
21
|
+
export declare function label(account: Account): {
|
|
22
|
+
title: string;
|
|
23
|
+
line: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The accounts signed in here, which is the reader's, and the two ways to leave
|
|
27
|
+
* for another: `switchTo` an account in the list, and `add` one. Signed out it
|
|
28
|
+
* reads nothing.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useAccounts(): {
|
|
31
|
+
accounts: Account[];
|
|
32
|
+
current: Account | null;
|
|
33
|
+
switchTo: (a: Account) => Promise<void>;
|
|
34
|
+
add: () => Promise<void>;
|
|
35
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* THE PEOPLE SIGNED IN ON THIS BROWSER, and the way to be any one of them.
|
|
4
|
+
*
|
|
5
|
+
* IAM's session cookie holds one session per person (GET /v1/iam/accounts lists
|
|
6
|
+
* them, most recent first; it answers the browser that holds them and no other).
|
|
7
|
+
* Being one of them is the ordinary sign-in with a `login_hint` naming the person:
|
|
8
|
+
* IAM continues as that account and nobody types anything. Adding another is the
|
|
9
|
+
* sign-in with `prompt=login`, which asks for credentials and keeps the sessions
|
|
10
|
+
* already held. Neither ends a session. Signing OUT is IAM's, and it ends every
|
|
11
|
+
* session the browser holds (internal/oidc/logout.go), so no row here offers to
|
|
12
|
+
* end just one.
|
|
13
|
+
*
|
|
14
|
+
* Both go through the page's own IAM client (`useClient`), so the authorize
|
|
15
|
+
* address is the one this site signs in at, and both write the page down first
|
|
16
|
+
* (`rememberDestination`), so the sign-in returns here.
|
|
17
|
+
*/
|
|
18
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
19
|
+
import { useIam } from '@hanzo/iam/react';
|
|
20
|
+
import { rememberDestination } from './destination.js';
|
|
21
|
+
import { named } from './session.js';
|
|
22
|
+
import { here, useClient } from './signout.js';
|
|
23
|
+
const PATH = '/v1/iam/accounts';
|
|
24
|
+
const text = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
25
|
+
/** One row of IAM's answer, or nothing for a row that cannot be named. Only an https picture is kept. */
|
|
26
|
+
function clean(raw) {
|
|
27
|
+
const r = (raw ?? {});
|
|
28
|
+
const sub = text(r.sub);
|
|
29
|
+
const name = text(r.name);
|
|
30
|
+
if (!sub || !name)
|
|
31
|
+
return null;
|
|
32
|
+
const avatar = text(r.avatar);
|
|
33
|
+
return {
|
|
34
|
+
sub,
|
|
35
|
+
owner: text(r.owner),
|
|
36
|
+
name,
|
|
37
|
+
displayName: text(r.displayName),
|
|
38
|
+
email: text(r.email).toLowerCase(),
|
|
39
|
+
avatar: avatar.startsWith('https://') ? avatar : '',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** The accounts IAM holds for this browser, read from `base`. An answer that is not a list, or none, is nobody. */
|
|
43
|
+
export async function read(base, signal) {
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(`${base.replace(/\/+$/, '')}${PATH}`, { credentials: 'include', headers: { Accept: 'application/json' }, signal });
|
|
46
|
+
if (!res.ok)
|
|
47
|
+
return [];
|
|
48
|
+
const body = (await res.json());
|
|
49
|
+
const rows = Array.isArray(body) ? body : body?.data;
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
return (Array.isArray(rows) ? rows : [])
|
|
52
|
+
.map(clean)
|
|
53
|
+
.filter((a) => a !== null && !seen.has(a.sub) && !!seen.add(a.sub));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Whether `account` is the reader: the same subject, else the same address, else the same username. */
|
|
60
|
+
export function is(account, who) {
|
|
61
|
+
if (who.sub && account.sub === who.sub)
|
|
62
|
+
return true;
|
|
63
|
+
if (who.email && account.email && account.email === who.email.trim().toLowerCase())
|
|
64
|
+
return true;
|
|
65
|
+
return !who.email && !!who.name && account.name === who.name;
|
|
66
|
+
}
|
|
67
|
+
/** The line a row says: the display name, else the username; and the address when it adds something. */
|
|
68
|
+
export function label(account) {
|
|
69
|
+
const title = account.displayName || account.name;
|
|
70
|
+
return { title, line: account.email && account.email !== title ? account.email : '' };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The accounts signed in here, which is the reader's, and the two ways to leave
|
|
74
|
+
* for another: `switchTo` an account in the list, and `add` one. Signed out it
|
|
75
|
+
* reads nothing.
|
|
76
|
+
*/
|
|
77
|
+
export function useAccounts() {
|
|
78
|
+
const { config, user, isAuthenticated } = useIam();
|
|
79
|
+
const client = useClient();
|
|
80
|
+
const [accounts, setAccounts] = useState([]);
|
|
81
|
+
const base = here() ? window.location.origin : config.serverUrl || '';
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!isAuthenticated || !base)
|
|
84
|
+
return;
|
|
85
|
+
const ctl = new AbortController();
|
|
86
|
+
void read(base, ctl.signal).then((list) => {
|
|
87
|
+
if (!ctl.signal.aborted)
|
|
88
|
+
setAccounts(list);
|
|
89
|
+
});
|
|
90
|
+
return () => ctl.abort();
|
|
91
|
+
}, [base, isAuthenticated]);
|
|
92
|
+
const claimed = named();
|
|
93
|
+
const u = user;
|
|
94
|
+
const who = { sub: u?.sub ?? u?.id, email: u?.email || claimed?.email, name: u?.name || claimed?.name };
|
|
95
|
+
const current = useMemo(() => accounts.find((a) => is(a, who)) ?? null, [accounts, who.sub, who.email, who.name]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
96
|
+
const go = useCallback(async (extra) => {
|
|
97
|
+
rememberDestination();
|
|
98
|
+
window.location.replace(await client.getSigninUrl(extra));
|
|
99
|
+
}, [client]);
|
|
100
|
+
const switchTo = useCallback((a) => go({ additionalParams: { login_hint: a.sub } }), [go]);
|
|
101
|
+
const add = useCallback(() => go({ additionalParams: { prompt: 'login' } }), [go]);
|
|
102
|
+
return { accounts, current, switchTo, add };
|
|
103
|
+
}
|
package/dist/lib/signout.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* session a person signs in with here is the one a later visit finds, and the
|
|
8
8
|
* one sign-out ends. Nobody is sent to hanzo.id for any of it.
|
|
9
9
|
*/
|
|
10
|
-
import { useMemo } from 'react';
|
|
10
|
+
import { useCallback, useMemo } from 'react';
|
|
11
11
|
import { IAM } from '@hanzo/iam';
|
|
12
12
|
import { useIam } from '@hanzo/iam/react';
|
|
13
13
|
import { useSignOut as useUiSignOut } from '@hanzo/ui/auth';
|
|
@@ -36,5 +36,12 @@ export const OUT = '/login?from=logout';
|
|
|
36
36
|
*/
|
|
37
37
|
export function useSignOut() {
|
|
38
38
|
// @ts-expect-error everywhere option added in @hanzo/ui / IAM shared sign-out
|
|
39
|
-
|
|
39
|
+
const signOut = useUiSignOut({ to: OUT, track, everywhere: true });
|
|
40
|
+
return useCallback(async () => {
|
|
41
|
+
// Google One Tap signs a returning person in on its own (`auto_select`), which
|
|
42
|
+
// would put them straight back in the account they just left. Leaving says so.
|
|
43
|
+
;
|
|
44
|
+
window.google?.accounts?.id?.disableAutoSelect?.();
|
|
45
|
+
await signOut();
|
|
46
|
+
}, [signOut]);
|
|
40
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|