Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

Account: Sessions inside Sign-in & security (PR 1929)

Janik29d16d4696ab
diff --git a/apps/web/src/settings/AssistantSettings.tsx b/apps/web/src/settings/AssistantSettings.tsx
index a25df2f2..b352cb71 100644
--- a/apps/web/src/settings/AssistantSettings.tsx
+++ b/apps/web/src/settings/AssistantSettings.tsx
@@ -53,7 +53,14 @@ import { Button, Icon, Note } from '../ui/kit.tsx'
import { Loading, LoadProblem, Skeleton, useLoading, useLoadState } from '../ui/LoadStates.tsx'
import { type SearchOption, SearchSelect } from '../ui/SearchSelect.tsx'
import { SettingRow } from '../ui/SettingRow.tsx'
-import { type PageSection, SettingsLayout, sectionHash, sectionParts, useSection } from '../ui/SettingsLayout.tsx'
+import {
+ type PageSection,
+ SettingsLayout,
+ scrollToWhileSettling,
+ sectionHash,
+ sectionParts,
+ useSection,
+} from '../ui/SettingsLayout.tsx'
import { StatusMark } from '../ui/StatusMark.tsx'
import { useWorkspaceCountry, useWorkspaceLanguage } from '../workspaceLocale.ts'
import { AgentSetupStrip } from './AgentChange.tsx'
@@ -1414,31 +1421,6 @@ function returnFromCalendarConnect(assistants: Assistant[]) {
if (assistant) history.replaceState(null, '', `#assistant/${assistant.id}/booking${query ? `?${query}` : ''}`)
}
-/** What ends the scroll to a linked place: the user moving the page themselves. */
-const USER_MOVES = ['wheel', 'touchstart', 'keydown', 'pointerdown'] as const
-
-/**
- * Scrolls to the element and keeps it there while the cards around it settle (a load that arrives after the first
- * frame makes the page taller), until the user moves the page or 2 s have passed. Returns the stop.
- */
-function scrollToWhileSettling(id: string): () => void {
- const element = document.getElementById(id)
- if (!element) return () => {}
- const scroll = () => element.scrollIntoView({ block: 'start' })
- scroll()
- const sizes = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(scroll)
- sizes?.observe(element)
- if (element.parentElement) sizes?.observe(element.parentElement)
- const stop = () => {
- sizes?.disconnect()
- clearTimeout(timer)
- for (const type of USER_MOVES) window.removeEventListener(type, stop, true)
- }
- const timer = setTimeout(stop, 2000)
- for (const type of USER_MOVES) window.addEventListener(type, stop, { capture: true, passive: true })
- return stop
-}
-
/** Old and short links in place (assistantLinks.ts): the address says what is on screen. */
function rewriteOldAssistantHash(assistants: Assistant[]) {
const next = canonicalAssistantHash(
diff --git a/apps/web/src/settings/account/index.tsx b/apps/web/src/settings/account/index.tsx
index 5d3e77b6..5bb49ac5 100644
--- a/apps/web/src/settings/account/index.tsx
+++ b/apps/web/src/settings/account/index.tsx
@@ -21,7 +21,13 @@ import { Input, onSaveKey, SaveBar, FormField } from '../../ui/form.tsx'
import { Avatar, Badge, Button, Note } from '../../ui/kit.tsx'
import { Loading, SkeletonText } from '../../ui/LoadStates.tsx'
import { SettingRow, SkeletonSettingRow, SkeletonSettingRows } from '../../ui/SettingRow.tsx'
-import { type PageSection, SettingsLayout, sectionParts, useSection } from '../../ui/SettingsLayout.tsx'
+import {
+ type PageSection,
+ SettingsLayout,
+ scrollToWhileSettling,
+ sectionParts,
+ useSection,
+} from '../../ui/SettingsLayout.tsx'
import { Section, TextInput } from '../fields.tsx'
import { AvatarField } from './AvatarField.tsx'
import {
@@ -859,6 +865,13 @@ function Authenticator() {
)
}
+/**
+ * The sessions card, the last of Sign-in & security: `#account/security/sessions` (and the old `#account/sessions`)
+ * scroll to it.
+ */
+const SESSIONS_CARD = 'ac-sessions'
+const SESSIONS_ITEM = 'sessions'
+
/** Sessions in the order shown; SignInAgain when the session is too old to list them. */
async function loadSessionList(): Promise<SessionRow[] | 'signInAgain'> {
try {
@@ -897,12 +910,24 @@ function AccountSkeleton({ current, error, retry }: { current: SectionId; error:
</div>
)
return (
- <Section id="ac-signin" title={t('account.nav.security.label')}>
- <Loading what={t('account.yourAccount')} loading error={error} onRetry={retry} skeleton={skeleton} />
- </Section>
+ <>
+ <Section id="ac-signin" title={t('account.nav.security.label')}>
+ <Loading what={t('account.yourAccount')} loading error={error} onRetry={retry} skeleton={skeleton} />
+ </Section>
+ <Section id={SESSIONS_CARD} title={t('account.sessions.title')}>
+ <Loading
+ what={t('account.sessions.title')}
+ loading
+ error={error}
+ onRetry={retry}
+ skeleton={<SkeletonSettingRows rows={3} control="button" />}
+ />
+ </Section>
+ </>
)
}
+/** Where you're signed in: one row per device, each signed out on its own, the others at once from the header. */
function Sessions() {
const t = useT()
const query = useQuery(SESSIONS, loadSessionList)
@@ -922,8 +947,8 @@ function Sessions() {
const others = sessions ? sessions.length - 1 : 0
return (
<Section
- id="ac-sessions"
- title={t('account.nav.sessions.label')}
+ id={SESSIONS_CARD}
+ title={t('account.sessions.title')}
// All the others at once: in the card's header like every card's own action, not a second button under the rows.
actions={
others > 0 && (
@@ -942,7 +967,7 @@ function Sessions() {
<SettingRow title={t('account.sessions.signInAgain')} control={<SignInAgainButton />} />
)}
<Loading
- what={t('account.nav.sessions.label')}
+ what={t('account.sessions.title')}
loading={!list}
error={query.error}
onRetry={() => void load()}
@@ -988,9 +1013,9 @@ function Sessions() {
}
// Language and notifications are under the profile card (LIN-837; `#account/preferences` and `#account/notifications`
-// open Profile, useRoute.ts MOVED).
-type SectionId = 'profile' | 'security' | 'sessions' | 'apiKeys'
-const SECTION_IDS: readonly SectionId[] = ['profile', 'security', 'sessions', 'apiKeys']
+// open Profile), sessions are the last card of Sign-in & security (`#account/sessions` opens it there; useRoute.ts MOVED).
+type SectionId = 'profile' | 'security' | 'apiKeys'
+const SECTION_IDS: readonly SectionId[] = ['profile', 'security', 'apiKeys']
/** The page's sections in the active language; without a workspace Profile has no notifications. Also listed on Settings (SettingsHome). */
export function useAccountSections(hasWorkspace: boolean): readonly PageSection<SectionId>[] {
@@ -1121,6 +1146,14 @@ function OwnAccount({ hasWorkspace }: Props) {
const props = account ? { account, reload } : null
// On a white-label partner's own address: the install's own, where sign-in methods, sessions and keys are managed.
const mainOrigin = account?.methods.mainOrigin
+ // `#account/security/sessions` (also where the old Sessions page's links land): Sign-in & security, at the sessions card,
+ // once the cards above it are there.
+ const address = window.location.hash
+ const item = sectionParts('account', movedHash(address) ?? address).item
+ const atSessions = current === 'security' && item === SESSIONS_ITEM && Boolean(props) && !mainOrigin
+ useEffect(() => {
+ if (atSessions) return scrollToWhileSettling(SESSIONS_CARD)
+ }, [atSessions])
return (
<div className="page">
<SettingsLayout
@@ -1142,12 +1175,16 @@ function OwnAccount({ hasWorkspace }: Props) {
<AccountSkeleton current={current} error={query.error} retry={() => void query.reload()} />
)}
{props && current === 'profile' && <ProfilePage {...props} hasWorkspace={hasWorkspace} />}
- {mainOrigin && (current === 'security' || current === 'sessions' || current === 'apiKeys') ? (
+ {mainOrigin && (current === 'security' || current === 'apiKeys') ? (
<MainHostOnly section={current} origin={mainOrigin} />
) : (
<>
- {props && current === 'security' && <SignIn {...props} />}
- {current === 'sessions' && <Sessions />}
+ {props && current === 'security' && (
+ <>
+ <SignIn {...props} />
+ <Sessions />
+ </>
+ )}
{current === 'apiKeys' && <PersonalKeys />}
</>
)}
diff --git a/apps/web/src/settings/account/legalLine.test.tsx b/apps/web/src/settings/account/legalLine.test.tsx
index 3ed92780..ea4180c6 100644
--- a/apps/web/src/settings/account/legalLine.test.tsx
+++ b/apps/web/src/settings/account/legalLine.test.tsx
@@ -45,7 +45,7 @@ beforeEach(() => {
})
afterEach(() => vi.unstubAllGlobals())
-test.each(['security', 'sessions', 'apiKeys'])('%s: Terms · Privacy at the foot, each in a new tab', section => {
+test.each(['security', 'apiKeys'])('%s: Terms · Privacy at the foot, each in a new tab', section => {
links = { terms: 'https://linedesk.ai/terms', privacy: 'https://linedesk.ai/privacy', supportEmail: null }
const html = render(`#account/${section}`)
expect(html).toContain('<nav class="auth-legal ac-legal" aria-label="Terms and privacy">')
diff --git a/apps/web/src/settings/account/mainHost.test.tsx b/apps/web/src/settings/account/mainHost.test.tsx
index 74f8cd23..ff86a817 100644
--- a/apps/web/src/settings/account/mainHost.test.tsx
+++ b/apps/web/src/settings/account/mainHost.test.tsx
@@ -32,7 +32,7 @@ const render = (hash: string) => {
}
afterEach(() => vi.unstubAllGlobals())
-test.each(['security', 'sessions', 'apiKeys'])('%s: a note and a link to the install’s own address', section => {
+test.each(['security', 'apiKeys'])('%s: a note and a link to the install’s own address', section => {
const html = render(`#account/${section}`)
expect(html).toContain('Done at the standard sign-in page')
expect(html).toContain(`href="https://app.linedesk.ai/#account/${section}"`)
diff --git a/apps/web/src/settings/account/sessionsInSecurity.test.tsx b/apps/web/src/settings/account/sessionsInSecurity.test.tsx
new file mode 100644
index 00000000..4d77c3df
--- /dev/null
+++ b/apps/web/src/settings/account/sessionsInSecurity.test.tsx
@@ -0,0 +1,48 @@
+// Sessions are the last card of Sign-in & security: no page of their own in the account's nav, and the old
+// `#account/sessions` link opens Sign-in & security with the sessions card.
+import { renderToStaticMarkup } from 'react-dom/server'
+import { afterEach, expect, test, vi } from 'vitest'
+
+const account = {
+ user: { name: 'Mike', email: '[email protected]', emailVerified: true, locale: null },
+ accounts: [],
+ methods: { password: false, emailCode: true, passkey: false, sso: [], links: {}, mainOrigin: null },
+ avatarUrl: null,
+ profileChangedBy: null,
+}
+const useQuery = vi.fn((key: unknown) =>
+ key === 'account' || (Array.isArray(key) && key[0] === 'account')
+ ? { data: account, error: null, reload: async () => {} }
+ : { data: undefined, error: null, reload: async () => {} },
+)
+vi.mock('../../cachedQuery.ts', async original => ({ ...(await original<object>()), useQuery }))
+
+const { AccountSettings } = await import('./index.tsx')
+const { movedHash } = await import('../../shell/useRoute.ts')
+
+const render = (hash: string) => {
+ vi.stubGlobal('window', { location: { hash }, addEventListener: () => {}, removeEventListener: () => {} })
+ return renderToStaticMarkup(<AccountSettings hasWorkspace />)
+}
+afterEach(() => vi.unstubAllGlobals())
+
+test('Sign-in & security ends with the sessions card', () => {
+ const html = render('#account/security')
+ expect(html).toContain('id="ac-signin"')
+ expect(html).toContain('id="ac-sessions"')
+ expect(html.indexOf('id="ac-signin"')).toBeLessThan(html.indexOf('id="ac-sessions"'))
+})
+
+test('the nav has no Sessions page', () => {
+ const html = render('#account/security')
+ expect(html).not.toContain('href="#account/sessions"')
+ expect(html).toContain('href="#account/security"')
+})
+
+test('the old #account/sessions lands on Sign-in & security, at the sessions card', () => {
+ const to = movedHash('#account/sessions')
+ expect(to).toBe('#account/security/sessions')
+ const html = render(to!)
+ expect(html).toContain('id="ac-signin"')
+ expect(html).toContain('id="ac-sessions"')
+})
diff --git a/apps/web/src/shell/useRoute.test.ts b/apps/web/src/shell/useRoute.test.ts
index 670e1387..5b7275ef 100644
--- a/apps/web/src/shell/useRoute.test.ts
+++ b/apps/web/src/shell/useRoute.test.ts
@@ -143,6 +143,9 @@ describe('old links (LIN-165)', () => {
['#account/notifications', '#account/profile'],
['#account/notifications?ws=ws_1', '#account/profile?ws=ws_1'],
['#account/preferences', '#account/profile'],
+ // Sessions became the last card of Sign-in & security.
+ ['#account/sessions', '#account/security/sessions'],
+ ['#account/sessions?ws=ws_1', '#account/security/sessions?ws=ws_1'],
['#settings/phone', '#workspace/phone'],
['#settings/phone/pn_1', '#workspace/phone/pn_1'],
['#settings/export', '#workspace/general/export'],
diff --git a/apps/web/src/shell/useRoute.ts b/apps/web/src/shell/useRoute.ts
index b5aa59eb..6546f44c 100644
--- a/apps/web/src/shell/useRoute.ts
+++ b/apps/web/src/shell/useRoute.ts
@@ -157,6 +157,8 @@ const MOVED: Record<string, string> = {
'account/notifications': 'account/profile',
// Preferences became a part of Profile (LIN-837).
'account/preferences': 'account/profile',
+ // Sessions became the last card of Sign-in & security.
+ 'account/sessions': 'account/security/sessions',
team: 'workspace/team',
// API keys and Zapier left Workspace settings for their own page (LIN-340).
'settings/developers': 'integrations/api-keys',
diff --git a/apps/web/src/ui/SettingsLayout.tsx b/apps/web/src/ui/SettingsLayout.tsx
index 0c4b206a..c47208b9 100644
--- a/apps/web/src/ui/SettingsLayout.tsx
+++ b/apps/web/src/ui/SettingsLayout.tsx
@@ -197,3 +197,28 @@ function SectionMarks({ section, dirty }: { section: PageSection; dirty: boolean
</>
)
}
+
+/** What ends the scroll to a linked place: the user moving the page themselves. */
+const USER_MOVES = ['wheel', 'touchstart', 'keydown', 'pointerdown'] as const
+
+/**
+ * Scrolls to the element and keeps it there while the cards around it settle (a load that arrives after the first
+ * frame makes the page taller), until the user moves the page or 2 s have passed. Returns the stop.
+ */
+export function scrollToWhileSettling(id: string): () => void {
+ const element = document.getElementById(id)
+ if (!element) return () => {}
+ const scroll = () => element.scrollIntoView({ block: 'start' })
+ scroll()
+ const sizes = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(scroll)
+ sizes?.observe(element)
+ if (element.parentElement) sizes?.observe(element.parentElement)
+ const stop = () => {
+ sizes?.disconnect()
+ clearTimeout(timer)
+ for (const type of USER_MOVES) window.removeEventListener(type, stop, true)
+ }
+ const timer = setTimeout(stop, 2000)
+ for (const type of USER_MOVES) window.addEventListener(type, stop, { capture: true, passive: true })
+ return stop
+}
diff --git a/packages/i18n/locales/de/account.json b/packages/i18n/locales/de/account.json
index b96f18c0..41d5aca7 100644
--- a/packages/i18n/locales/de/account.json
+++ b/packages/i18n/locales/de/account.json
@@ -133,8 +133,6 @@
"nav.profile.label": "Profil",
"nav.security.description": "Anmeldemethoden, Passkeys und Passwort",
"nav.security.label": "Anmeldung & Sicherheit",
- "nav.sessions.description": "Wo du angemeldet bist",
- "nav.sessions.label": "Sitzungen",
"notify.blocked": "Vom Browser blockiert. Erlaube Benachrichtigungen für diese Seite und versuch es dann noch einmal.",
"notify.card.assigned": "eine E-Mail, wenn dir ein Anruf zugewiesen wird",
"notify.card.deviceOpen": "Benachrichtigungen auf diesem Gerät, solange {brand} geöffnet ist",
diff --git a/packages/i18n/locales/en/account.json b/packages/i18n/locales/en/account.json
index 458f79bc..e4886975 100644
--- a/packages/i18n/locales/en/account.json
+++ b/packages/i18n/locales/en/account.json
@@ -133,10 +133,8 @@
"nav.profile.description": "Your picture, name and language",
"nav.profile.descriptionNotify": "Your picture, name, language and notifications",
"nav.profile.label": "Profile",
- "nav.security.description": "Sign-in methods, passkeys and password",
+ "nav.security.description": "Sign-in methods, passkeys, password and sessions",
"nav.security.label": "Sign-in & security",
- "nav.sessions.description": "Where you are signed in",
- "nav.sessions.label": "Sessions",
"notify.blocked": "Blocked by the browser. Allow notifications for this site, then try again.",
"notify.card.assigned": "an email when a call is assigned to you",
"notify.card.deviceOpen": "notifications on this device while {brand} is open",
@@ -254,6 +252,7 @@
"sessions.signOutOthersTitle": "Sign out everywhere except this device",
"sessions.signedOut": "Session signed out.",
"sessions.thisDevice": "This device",
+ "sessions.title": "Sessions",
"signInAgain.button": "Sign in again",
"signInAgain.title": "Sign out and sign in again, then come back here",
"signInAgain.toAddPasskey": "Sign in again to add a passkey.",
diff --git a/packages/i18n/locales/es/account.json b/packages/i18n/locales/es/account.json
index 7983d809..95537bf1 100644
--- a/packages/i18n/locales/es/account.json
+++ b/packages/i18n/locales/es/account.json
@@ -133,8 +133,6 @@
"nav.profile.label": "Perfil",
"nav.security.description": "Métodos de inicio de sesión, llaves de acceso y contraseña",
"nav.security.label": "Inicio de sesión y seguridad",
- "nav.sessions.description": "Dónde tienes la sesión iniciada",
- "nav.sessions.label": "Sesiones",
"notify.blocked": "Bloqueadas por el navegador. Permite las notificaciones para este sitio e inténtalo de nuevo.",
"notify.card.assigned": "un correo cuando se te asigna una llamada",
"notify.card.deviceOpen": "notificaciones en este dispositivo mientras {brand} está abierto",
diff --git a/packages/i18n/locales/fr/account.json b/packages/i18n/locales/fr/account.json
index dfa50e18..9d3cd085 100644
--- a/packages/i18n/locales/fr/account.json
+++ b/packages/i18n/locales/fr/account.json
@@ -133,8 +133,6 @@
"nav.profile.label": "Profil",
"nav.security.description": "Méthodes de connexion, clés d'accès et mot de passe",
"nav.security.label": "Connexion et sécurité",
- "nav.sessions.description": "Là où vous êtes connecté",
- "nav.sessions.label": "Sessions",
"notify.blocked": "Bloquées par le navigateur. Autorisez les notifications pour ce site, puis réessayez.",
"notify.card.assigned": "un e-mail quand un appel vous est attribué",
"notify.card.deviceOpen": "des notifications sur cet appareil quand {brand} est ouvert",
diff --git a/packages/i18n/locales/ja/account.json b/packages/i18n/locales/ja/account.json
index 97e244ec..3a5499e2 100644
--- a/packages/i18n/locales/ja/account.json
+++ b/packages/i18n/locales/ja/account.json
@@ -133,8 +133,6 @@
"nav.profile.label": "プロフィール",
"nav.security.description": "サインイン方法、パスキー、パスワード",
"nav.security.label": "サインインとセキュリティ",
- "nav.sessions.description": "サインイン中の場所",
- "nav.sessions.label": "セッション",
"notify.blocked": "ブラウザでブロックされています。このサイトの通知を許可してから、もう一度お試しください。",
"notify.card.assigned": "通話が自分に割り当てられたときのメール",
"notify.card.deviceOpen": "{brand}を開いている間のこのデバイスへの通知",
diff --git a/packages/i18n/locales/pt-BR/account.json b/packages/i18n/locales/pt-BR/account.json
index aac4b04d..fb1a0f77 100644
--- a/packages/i18n/locales/pt-BR/account.json
+++ b/packages/i18n/locales/pt-BR/account.json
@@ -133,8 +133,6 @@
"nav.profile.label": "Perfil",
"nav.security.description": "Métodos de login, chaves de acesso e senha",
"nav.security.label": "Login e segurança",
- "nav.sessions.description": "Onde você está conectado",
- "nav.sessions.label": "Sessões",
"notify.blocked": "Bloqueadas pelo navegador. Permita notificações para este site e tente novamente.",
"notify.card.assigned": "um e-mail quando uma chamada for atribuída a você",
"notify.card.deviceOpen": "notificações neste dispositivo enquanto o {brand} estiver aberto",