feat: a password for each app or device
A person can make a password for each app that connects to their server, in
Settings, Apps and devices. The secret is shown once, can be taken back, and
is for the music API of other apps only: it cannot sign in or change the
account. Secrets are kept sealed (AES-256-GCM, key derived from the jwt secret)
because token login needs them in clear, and a hash finds a device by its key.
- migration 0034 device_passwords (sqlite, postgres)
- internal/devices service, storage repo
- GET/POST /me/devices, DELETE /me/devices/{id}, in the OpenAPI spec
- Settings section with copy and remove
This commit is contained in:
parent
9451765861
commit
010f2e5057
8 changed files with 1368 additions and 11 deletions
31
web/src/api/devices.ts
Normal file
31
web/src/api/devices.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api } from '@/api/client'
|
||||
import type { components } from '@/api/schema'
|
||||
|
||||
export type Device = components['schemas']['Device']
|
||||
export type CreatedDevice = components['schemas']['CreatedDevice']
|
||||
type DeviceList = components['schemas']['DeviceList']
|
||||
|
||||
const KEY = ['me', 'devices']
|
||||
|
||||
/** The passwords this person made for their apps and devices. The secrets are never in the list. */
|
||||
export function useDevices() {
|
||||
return useQuery({ queryKey: KEY, queryFn: async () => (await api.get<DeviceList>('/me/devices')).devices })
|
||||
}
|
||||
|
||||
/** Makes a password. The answer holds the secret, which the server never sends again. */
|
||||
export function useCreateDevice() {
|
||||
const client = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (name: string) => api.post<CreatedDevice>('/me/devices', { name }),
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: KEY }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteDevice() {
|
||||
const client = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => api.del<void>(`/me/devices/${id}`),
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: KEY }),
|
||||
})
|
||||
}
|
||||
170
web/src/api/schema.d.ts
vendored
170
web/src/api/schema.d.ts
vendored
|
|
@ -1620,6 +1620,54 @@ export interface paths {
|
|||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/me/devices": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* The passwords of your apps and devices
|
||||
* @description The device passwords you made for other apps (OpenSubsonic clients), newest first. The secret is never sent
|
||||
* back: it was shown once, when the password was made.
|
||||
*/
|
||||
get: operations["listMyDevices"];
|
||||
put?: never;
|
||||
/**
|
||||
* Make a password for an app or device
|
||||
* @description Makes a password for one app or device and returns it. **The secret is shown only in this answer**: copy it into
|
||||
* the app now. It opens the music API for other apps and nothing else: it cannot sign in to Sonda, change your
|
||||
* account or make more passwords. Make one for each app, so that you can take back one without the others. You can
|
||||
* have up to 20. The body must be one JSON object with the name and nothing else.
|
||||
*/
|
||||
post: operations["createMyDevice"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/me/devices/{id}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
post?: never;
|
||||
/**
|
||||
* Take back the password of a device
|
||||
* @description Takes back the password, so the app that had it can no longer connect. Only your own devices.
|
||||
*/
|
||||
delete: operations["deleteMyDevice"];
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/me/import/spotify": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
|
|
@ -4206,6 +4254,34 @@ export interface components {
|
|||
}[];
|
||||
};
|
||||
};
|
||||
Device: {
|
||||
/** Format: int64 */
|
||||
id: number;
|
||||
name: string;
|
||||
/** Format: date-time */
|
||||
created_at: string;
|
||||
/**
|
||||
* Format: date-time
|
||||
* @description When an app last connected with it. Absent until it does.
|
||||
*/
|
||||
last_used_at?: string;
|
||||
};
|
||||
DeviceList: {
|
||||
devices: components["schemas"]["Device"][];
|
||||
};
|
||||
CreateDevice: {
|
||||
/** @description What this password is for, like `Phone` or `Feishin on the laptop`. */
|
||||
name: string;
|
||||
};
|
||||
CreatedDevice: {
|
||||
/** Format: int64 */
|
||||
id: number;
|
||||
name: string;
|
||||
/** Format: date-time */
|
||||
created_at: string;
|
||||
/** @description The password, 48 characters. Shown only here: it is never sent again. */
|
||||
secret: string;
|
||||
};
|
||||
MastodonAccount: {
|
||||
connected: boolean;
|
||||
/** @description The instance, like `https://mastodon.social`. Only when connected. */
|
||||
|
|
@ -7124,6 +7200,100 @@ export interface operations {
|
|||
401: components["responses"]["Unauthorized"];
|
||||
};
|
||||
};
|
||||
listMyDevices: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Your devices. */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["DeviceList"];
|
||||
};
|
||||
};
|
||||
401: components["responses"]["Unauthorized"];
|
||||
};
|
||||
};
|
||||
createMyDevice: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["CreateDevice"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description The device, with its secret. */
|
||||
201: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["CreatedDevice"];
|
||||
};
|
||||
};
|
||||
/** @description The body is malformed (`invalid_input`) or the name is empty or longer than 60 characters (`invalid_name`). */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
401: components["responses"]["Unauthorized"];
|
||||
/** @description You have 20 devices already (`too_many_devices`). */
|
||||
409: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
deleteMyDevice: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: number;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Taken back. */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
401: components["responses"]["Unauthorized"];
|
||||
/** @description There is no such device of yours (`device_not_found`). */
|
||||
404: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
listMySpotifyImports: {
|
||||
parameters: {
|
||||
query?: {
|
||||
|
|
|
|||
125
web/src/components/DevicesBlock.test.tsx
Normal file
125
web/src/components/DevicesBlock.test.tsx
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, expect, test, vi } from 'vitest'
|
||||
import { sessionStore } from '@/auth/session'
|
||||
import { initI18n } from '@/i18n'
|
||||
import { apiError, mockFetch, type MockRoutes } from '@/test/mockFetch'
|
||||
import DevicesBlock from './DevicesBlock'
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
|
||||
await initI18n()
|
||||
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: false } })
|
||||
})
|
||||
|
||||
interface Dev {
|
||||
id: number
|
||||
name: string
|
||||
created_at: string
|
||||
last_used_at?: string
|
||||
}
|
||||
|
||||
const phone: Dev = { id: 2, name: 'Phone', created_at: '2026-11-10T12:00:00Z', last_used_at: '2026-11-15T12:00:00Z' }
|
||||
const laptop: Dev = { id: 1, name: 'Laptop', created_at: '2026-11-01T12:00:00Z' }
|
||||
|
||||
function setup(initial: Dev[], over: MockRoutes = {}) {
|
||||
let devices = initial
|
||||
const mocked = mockFetch({
|
||||
'GET /api/v1/me/devices': () => ({ devices }),
|
||||
'POST /api/v1/me/devices': ({ init }) => {
|
||||
const made = { id: 9, name: JSON.parse(String(init.body)).name, created_at: '2026-11-16T09:00:00Z' }
|
||||
devices = [made, ...devices]
|
||||
return new Response(JSON.stringify({ ...made, secret: 'ab'.repeat(24) }), { status: 201, headers: { 'Content-Type': 'application/json' } })
|
||||
},
|
||||
'DELETE /api/v1/me/devices/2': () => {
|
||||
devices = devices.filter((d) => d.id !== 2)
|
||||
return new Response(null, { status: 204 })
|
||||
},
|
||||
...over,
|
||||
})
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })}>
|
||||
<DevicesBlock />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
return mocked
|
||||
}
|
||||
|
||||
test('it says what a device password is for, and lists the devices with when they were used', async () => {
|
||||
setup([phone, laptop])
|
||||
expect(await screen.findByText('Phone')).toBeInTheDocument()
|
||||
const list = screen.getByRole('list', { name: 'Your devices' })
|
||||
const rows = within(list).getAllByRole('listitem')
|
||||
expect(rows).toHaveLength(2)
|
||||
expect(rows[0]).toHaveTextContent(/Last used Nov 15, 2026/)
|
||||
expect(rows[1]).toHaveTextContent('Never used')
|
||||
expect(screen.getByText(/other apps/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('with no device there is no list, only the form', async () => {
|
||||
setup([])
|
||||
expect(await screen.findByLabelText('Name of the app or device')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('list', { name: 'Your devices' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('making a password shows it once with the sign-in details, and the list gets the device', async () => {
|
||||
const { calls } = setup([laptop])
|
||||
await userEvent.type(await screen.findByLabelText('Name of the app or device'), ' Feishin ')
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Make password' }))
|
||||
|
||||
const shown = await screen.findByRole('region', { name: 'Password for Feishin' })
|
||||
expect(within(shown).getByText('ab'.repeat(24))).toBeInTheDocument()
|
||||
expect(within(shown).getByText('tom@example.org')).toBeInTheDocument()
|
||||
expect(within(shown).getByText(window.location.origin)).toBeInTheDocument()
|
||||
expect(within(shown).getByText(/only time/)).toBeInTheDocument()
|
||||
expect(JSON.parse(String(calls.find((c) => c.key === 'POST /api/v1/me/devices')!.init.body))).toEqual({ name: 'Feishin' })
|
||||
|
||||
await userEvent.click(within(shown).getByRole('button', { name: 'Done' }))
|
||||
expect(screen.queryByRole('region', { name: 'Password for Feishin' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('ab'.repeat(24))).not.toBeInTheDocument()
|
||||
expect(await screen.findByText('Feishin')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('the form is empty again after a password is made', async () => {
|
||||
setup([])
|
||||
const name = await screen.findByLabelText('Name of the app or device')
|
||||
await userEvent.type(name, 'Phone')
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Make password' }))
|
||||
await screen.findByRole('region', { name: 'Password for Phone' })
|
||||
expect(screen.getByLabelText('Name of the app or device')).toHaveValue('')
|
||||
})
|
||||
|
||||
test('copying the password puts it on the clipboard', async () => {
|
||||
const writeText = vi.fn().mockResolvedValue(undefined)
|
||||
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
|
||||
setup([])
|
||||
await userEvent.type(await screen.findByLabelText('Name of the app or device'), 'Phone')
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Make password' }))
|
||||
await userEvent.click(await screen.findByRole('button', { name: 'Copy password' }))
|
||||
expect(writeText).toHaveBeenCalledWith('ab'.repeat(24))
|
||||
})
|
||||
|
||||
test('taking back a password removes the device from the list', async () => {
|
||||
const { calls } = setup([phone, laptop])
|
||||
await userEvent.click(await screen.findByRole('button', { name: 'Remove Phone' }))
|
||||
expect(await screen.findByText('Laptop')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Phone')).not.toBeInTheDocument()
|
||||
expect(calls.some((c) => c.key === 'DELETE /api/v1/me/devices/2')).toBe(true)
|
||||
})
|
||||
|
||||
test('a name that is refused says why, and a full list says to remove one', async () => {
|
||||
setup([], { 'POST /api/v1/me/devices': () => apiError(409, 'too_many_devices', 'x') })
|
||||
await userEvent.type(await screen.findByLabelText('Name of the app or device'), 'Phone')
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Make password' }))
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('You have 20 devices. Remove one first.')
|
||||
})
|
||||
|
||||
test('a list that cannot be read has a way to try again', async () => {
|
||||
let fail = true
|
||||
setup([], { 'GET /api/v1/me/devices': () => (fail ? apiError(500, 'internal', 'x') : { devices: [laptop] }) })
|
||||
const retry = await screen.findByRole('button', { name: 'Try again' })
|
||||
fail = false
|
||||
await userEvent.click(retry)
|
||||
expect(await screen.findByText('Laptop')).toBeInTheDocument()
|
||||
})
|
||||
128
web/src/components/DevicesBlock.tsx
Normal file
128
web/src/components/DevicesBlock.tsx
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { useState, type FormEvent } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ApiError } from '@/api/client'
|
||||
import { useCreateDevice, useDeleteDevice, useDevices, type CreatedDevice } from '@/api/devices'
|
||||
import { useSession } from '@/auth/session'
|
||||
import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { errorMessageKey } from '@/i18n'
|
||||
|
||||
/** One line of the details an app asks for: what it is called there, and the value to type. */
|
||||
function Detail({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<dt className="text-sm text-muted-foreground">{label}</dt>
|
||||
<dd className="break-all font-semibold select-all">{value}</dd>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The password that was just made, with what to type in the app. It is shown here once and never again. */
|
||||
function NewPassword({ device, onDone }: { device: CreatedDevice; onDone: () => void }) {
|
||||
const { t } = useTranslation()
|
||||
const { user } = useSession()
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
function copy() {
|
||||
void navigator.clipboard?.writeText(device.secret).then(() => setCopied(true), () => undefined)
|
||||
}
|
||||
|
||||
return (
|
||||
<section aria-label={t('devices.passwordFor', { name: device.name })} className="flex max-w-xl flex-col gap-4">
|
||||
<p className="font-semibold">{t('devices.once')}</p>
|
||||
<dl className="flex flex-col gap-3">
|
||||
<Detail label={t('devices.server')} value={window.location.origin} />
|
||||
<Detail label={t('devices.username')} value={user?.email ?? ''} />
|
||||
<Detail label={t('devices.password')} value={device.secret} />
|
||||
</dl>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button onClick={copy}>{copied ? t('devices.copied') : t('devices.copy')}</Button>
|
||||
<Button variant="outline" onClick={onDone}>
|
||||
{t('devices.done')}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The passwords for other apps. Each app gets its own, shown once when it is made, so that one can be taken back
|
||||
* without the others. A device password opens the music of this server in that app and nothing else.
|
||||
*/
|
||||
export default function DevicesBlock() {
|
||||
const { t, i18n } = useTranslation()
|
||||
const devices = useDevices()
|
||||
const create = useCreateDevice()
|
||||
const remove = useDeleteDevice()
|
||||
const [name, setName] = useState('')
|
||||
const [made, setMade] = useState<CreatedDevice | null>(null)
|
||||
|
||||
function submit(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
create.mutate(name.trim(), {
|
||||
onSuccess: (device) => {
|
||||
setName('')
|
||||
setMade(device)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (devices.isError) return <ErrorMessage error={devices.error} onRetry={() => void devices.refetch()} />
|
||||
if (devices.isPending) return <Loading />
|
||||
|
||||
const when = (iso: string) => new Intl.DateTimeFormat(i18n.language, { dateStyle: 'medium' }).format(new Date(iso))
|
||||
const error = create.error ?? remove.error
|
||||
|
||||
return (
|
||||
<div className="flex max-w-xl flex-col gap-6">
|
||||
<p className="text-muted-foreground">{t('devices.intro')}</p>
|
||||
|
||||
{made && <NewPassword device={made} onDone={() => setMade(null)} />}
|
||||
|
||||
{devices.data.length === 0 ? (
|
||||
!made && <EmptyMessage>{t('devices.none')}</EmptyMessage>
|
||||
) : (
|
||||
<ul aria-label={t('devices.list')} className="flex flex-col gap-3">
|
||||
{devices.data.map((d) => (
|
||||
<li key={d.id} className="flex items-center justify-between gap-4">
|
||||
<div className="flex min-w-0 flex-col">
|
||||
<span className="truncate font-semibold">{d.name}</span>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{d.last_used_at ? t('devices.lastUsed', { date: when(d.last_used_at) }) : t('devices.neverUsed')}
|
||||
</span>
|
||||
</div>
|
||||
<Button variant="outline" aria-label={t('devices.removeNamed', { name: d.name })} disabled={remove.isPending} onClick={() => remove.mutate(d.id)}>
|
||||
{t('devices.remove')}
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<form onSubmit={submit} className="flex flex-col gap-3">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="device-name">{t('devices.name')}</Label>
|
||||
<Input
|
||||
id="device-name"
|
||||
autoComplete="off"
|
||||
maxLength={60}
|
||||
placeholder={t('devices.namePlaceholder')}
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{error && (
|
||||
<p role="alert" className="text-sm text-destructive">
|
||||
{t(errorMessageKey(error instanceof ApiError ? error.code : 'unknown'))}
|
||||
</p>
|
||||
)}
|
||||
<Button type="submit" className="self-start" disabled={create.isPending || name.trim() === ''}>
|
||||
{create.isPending ? t('devices.making') : t('devices.make')}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -84,6 +84,27 @@
|
|||
"connectedHelp": "Each song that counts as a listen is posted as an unlisted status with #NowPlaying. Music of a friend is never posted.",
|
||||
"disconnect": "Disconnect"
|
||||
},
|
||||
"devices": {
|
||||
"intro": "Make a password for each of your other apps that plays music from this server, like Feishin, Symfonium or Amperfy. It opens the music of this server in that app and nothing else: it cannot sign in here or change your account. You can take it back at any time.",
|
||||
"none": "No app has a password yet.",
|
||||
"list": "Your devices",
|
||||
"lastUsed": "Last used {{date}}",
|
||||
"neverUsed": "Never used",
|
||||
"remove": "Remove",
|
||||
"removeNamed": "Remove {{name}}",
|
||||
"name": "Name of the app or device",
|
||||
"namePlaceholder": "Phone",
|
||||
"make": "Make password",
|
||||
"making": "Making…",
|
||||
"passwordFor": "Password for {{name}}",
|
||||
"once": "This is the only time the password is shown. Copy it into the app now.",
|
||||
"server": "Server",
|
||||
"username": "Username",
|
||||
"password": "Password",
|
||||
"copy": "Copy password",
|
||||
"copied": "Copied",
|
||||
"done": "Done"
|
||||
},
|
||||
"settings": {
|
||||
"account": "Account",
|
||||
"admin": "Admin",
|
||||
|
|
@ -116,7 +137,8 @@
|
|||
"passwordLength": "The new password needs 8 to 256 characters.",
|
||||
"currentPasswordWrong": "The current password is wrong.",
|
||||
"changePassword": "Change password",
|
||||
"about": "About"
|
||||
"about": "About",
|
||||
"devices": "Apps and devices"
|
||||
},
|
||||
"admin": {
|
||||
"title": "Admin",
|
||||
|
|
@ -809,7 +831,10 @@
|
|||
"mix_empty": "This mix has no songs to keep.",
|
||||
"smart_playlist_not_found": "This smart playlist does not exist.",
|
||||
"suggested_not_found": "This suggested smart playlist does not exist.",
|
||||
"smart_playlist_empty": "These rules give no songs to keep."
|
||||
"smart_playlist_empty": "These rules give no songs to keep.",
|
||||
"invalid_name": "The name needs 1 to 60 characters.",
|
||||
"too_many_devices": "You have 20 devices. Remove one first.",
|
||||
"device_not_found": "That device is already removed."
|
||||
},
|
||||
"spotify": {
|
||||
"intro": "Bring in your listening history and your playlists from Spotify, so that your mixes, Discover and smart playlists know what you listened to before. Ask Spotify for your data (Account, Privacy, “Extended streaming history” and “Account data”), then choose the zip it sends you, or the JSON files inside it.",
|
||||
|
|
|
|||
|
|
@ -84,6 +84,27 @@
|
|||
"connectedHelp": "Ogni brano che conta come ascolto viene pubblicato come post non in elenco con #NowPlaying. La musica di un amico non viene mai pubblicata.",
|
||||
"disconnect": "Scollega"
|
||||
},
|
||||
"devices": {
|
||||
"intro": "Crea una password per ognuna delle altre app che riproduce la musica di questo server, come Feishin, Symfonium o Amperfy. Apre la musica di questo server in quell'app e nient'altro: non può accedere qui né cambiare il tuo account. Puoi ritirarla quando vuoi.",
|
||||
"none": "Nessuna app ha ancora una password.",
|
||||
"list": "I tuoi dispositivi",
|
||||
"lastUsed": "Ultimo uso {{date}}",
|
||||
"neverUsed": "Mai usata",
|
||||
"remove": "Rimuovi",
|
||||
"removeNamed": "Rimuovi {{name}}",
|
||||
"name": "Nome dell'app o del dispositivo",
|
||||
"namePlaceholder": "Telefono",
|
||||
"make": "Crea password",
|
||||
"making": "Creo…",
|
||||
"passwordFor": "Password per {{name}}",
|
||||
"once": "Questa è l'unica volta che la password viene mostrata. Copiala subito nell'app.",
|
||||
"server": "Server",
|
||||
"username": "Nome utente",
|
||||
"password": "Password",
|
||||
"copy": "Copia password",
|
||||
"copied": "Copiata",
|
||||
"done": "Fatto"
|
||||
},
|
||||
"settings": {
|
||||
"account": "Account",
|
||||
"admin": "Admin",
|
||||
|
|
@ -116,7 +137,8 @@
|
|||
"passwordLength": "La nuova password deve avere da 8 a 256 caratteri.",
|
||||
"currentPasswordWrong": "La password attuale è sbagliata.",
|
||||
"changePassword": "Cambia password",
|
||||
"about": "Informazioni"
|
||||
"about": "Informazioni",
|
||||
"devices": "App e dispositivi"
|
||||
},
|
||||
"admin": {
|
||||
"title": "Admin",
|
||||
|
|
@ -809,7 +831,10 @@
|
|||
"mix_empty": "Questo mix non ha brani da salvare.",
|
||||
"smart_playlist_not_found": "Questa playlist smart non esiste.",
|
||||
"suggested_not_found": "Questa playlist smart suggerita non esiste.",
|
||||
"smart_playlist_empty": "Con queste regole non ci sono brani da salvare."
|
||||
"smart_playlist_empty": "Con queste regole non ci sono brani da salvare.",
|
||||
"invalid_name": "Il nome deve avere da 1 a 60 caratteri.",
|
||||
"too_many_devices": "Hai già 20 dispositivi. Rimuovine uno.",
|
||||
"device_not_found": "Quel dispositivo è già stato rimosso."
|
||||
},
|
||||
"spotify": {
|
||||
"intro": "Porta qui la cronologia di ascolto e le playlist di Spotify, così i tuoi mix, Discover e le playlist smart sanno cosa ascoltavi prima. Chiedi a Spotify i tuoi dati (Account, Privacy, «Cronologia di streaming estesa» e «Dati dell'account»), poi scegli lo zip che ti manda, oppure i file JSON che contiene.",
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ function renderSettings() {
|
|||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
mockFetch({ 'GET /api/v1/me/settings': () => ({ discover_from_listening: false }), 'GET /api/v1/me/mastodon': () => ({ connected: false }), 'GET /api/v1/version': () => ({ version: '0.1.0', revision: '69c85a7' }) })
|
||||
mockFetch({ 'GET /api/v1/me/settings': () => ({ discover_from_listening: false }), 'GET /api/v1/me/mastodon': () => ({ connected: false }), 'GET /api/v1/me/devices': () => ({ devices: [] }), 'GET /api/v1/version': () => ({ version: '0.1.0', revision: '69c85a7' }) })
|
||||
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
|
||||
await initI18n()
|
||||
initTheme()
|
||||
|
|
@ -119,7 +119,7 @@ test('Discover has its own group with the switch for using your listening, off u
|
|||
})
|
||||
|
||||
test('a new password of seven characters is refused here, with no request', async () => {
|
||||
const { calls } = mockFetch({})
|
||||
const { calls } = mockFetch({ 'GET /api/v1/me/devices': () => ({ devices: [] }) })
|
||||
renderSettings()
|
||||
await changePassword('old-password', '1234567')
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('The new password needs 8 to 256 characters.')
|
||||
|
|
@ -127,7 +127,7 @@ test('a new password of seven characters is refused here, with no request', asyn
|
|||
})
|
||||
|
||||
test('a new password longer than 256 bytes is refused here, with no request', async () => {
|
||||
const { calls } = mockFetch({})
|
||||
const { calls } = mockFetch({ 'GET /api/v1/me/devices': () => ({ devices: [] }) })
|
||||
renderSettings()
|
||||
await userEvent.type(screen.getByLabelText('Current password'), 'old-password')
|
||||
await userEvent.click(screen.getByLabelText('New password'))
|
||||
|
|
@ -153,7 +153,7 @@ test('a changed password signs this session out, because the server ends every s
|
|||
})
|
||||
|
||||
test('a wrong current password is explained and keeps the session', async () => {
|
||||
mockFetch({ 'POST /api/v1/auth/password': () => apiError(403, 'invalid_credentials') })
|
||||
mockFetch({ 'GET /api/v1/me/devices': () => ({ devices: [] }), 'POST /api/v1/auth/password': () => apiError(403, 'invalid_credentials') })
|
||||
renderSettings()
|
||||
await changePassword('not-my-password', 'new-password-1')
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('The current password is wrong.')
|
||||
|
|
@ -161,7 +161,7 @@ test('a wrong current password is explained and keeps the session', async () =>
|
|||
})
|
||||
|
||||
test('a password change that fails for another reason says so', async () => {
|
||||
mockFetch({ 'POST /api/v1/auth/password': () => apiError(500, 'internal') })
|
||||
mockFetch({ 'GET /api/v1/me/devices': () => ({ devices: [] }), 'POST /api/v1/auth/password': () => apiError(500, 'internal') })
|
||||
renderSettings()
|
||||
await changePassword('old-password', 'new-password-1')
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('Something went wrong. Try again.')
|
||||
|
|
@ -246,3 +246,9 @@ test('the page says which version of Sonda this is', async () => {
|
|||
renderSettings()
|
||||
expect(await screen.findByText('Version 0.1.0 · 69c85a7')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('it has a section for the passwords of other apps', async () => {
|
||||
renderSettings()
|
||||
expect(await screen.findByRole('heading', { name: 'Apps and devices' })).toBeInTheDocument()
|
||||
expect(await screen.findByLabelText('Name of the app or device')).toBeInTheDocument()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { api, ApiError } from '@/api/client'
|
|||
import { logout, useSession } from '@/auth/session'
|
||||
import ChoiceGroup from '@/components/ChoiceGroup'
|
||||
import ListeningSwitch from '@/components/ListeningSwitch'
|
||||
import DevicesBlock from '@/components/DevicesBlock'
|
||||
import MastodonBlock from '@/components/MastodonBlock'
|
||||
import Section from '@/components/Section'
|
||||
import VersionLabel from '@/components/VersionLabel'
|
||||
|
|
@ -185,6 +186,10 @@ export default function SettingsPage() {
|
|||
<MastodonBlock />
|
||||
</Section>
|
||||
|
||||
<Section title={t('settings.devices')}>
|
||||
<DevicesBlock />
|
||||
</Section>
|
||||
|
||||
<Section title={t('settings.spotify')}>
|
||||
<p className="max-w-xl">{t('settings.importHint')}</p>
|
||||
<Link to="/import" className="self-start font-semibold underline underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring">
|
||||
|
|
|
|||
Loading…
Reference in a new issue