dacb8b9278
Replace the faked ConnectPage login with a real /auth/login -> /auth/me
flow, including loading/error states. Add a backend-contract adapter layer
(api/mappers.ts) translating the backend's snake_case, lean *Out schemas and
{items,total,limit,offset} paging into the UI's camelCase domain types, so
swapping backends only touches the mappers.
- auth: chained login (tokens) + /auth/me (user); refresh on snake_case;
expiresIn optional (reauth is 401-driven, backend sends no TTL)
- streaming: GET /stream/{id}?token= (token query param for <audio>); SW
audio cache route + tests follow the path change (token stays cache-stable)
- library/playlists/likes/admin: correct paths (/tracks not /library/tracks),
page/pageSize<->limit/offset, duration_seconds->durationMs, likes as
append-only POST /likes event-log, admin is_superuser<->role
- downloads/storage: marked provisional (backend routes still stubs)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { api } from '../index';
|
|
import { toUser, type RawUser } from '../mappers';
|
|
import type { User } from '../types';
|
|
|
|
/**
|
|
* Admin user management. The backend models authorization as `is_superuser` /
|
|
* `is_active` (no `role`/`email`); `toUser` maps superuser→role for the UI and
|
|
* the mutations translate role back to `is_superuser` on the way out.
|
|
*/
|
|
export const adminApi = api.injectEndpoints({
|
|
endpoints: (build) => ({
|
|
getUsers: build.query<User[], void>({
|
|
query: () => '/admin/users',
|
|
transformResponse: (raw: RawUser[]) => raw.map(toUser),
|
|
providesTags: ['User'],
|
|
}),
|
|
createUser: build.mutation<
|
|
User,
|
|
{ username: string; password: string; role: 'admin' | 'user' }
|
|
>({
|
|
query: ({ username, password, role }) => ({
|
|
url: '/admin/users',
|
|
method: 'POST',
|
|
body: { username, password, is_superuser: role === 'admin' },
|
|
}),
|
|
transformResponse: (raw: RawUser) => toUser(raw),
|
|
invalidatesTags: ['User'],
|
|
}),
|
|
updateUser: build.mutation<
|
|
User,
|
|
{ id: string; role?: 'admin' | 'user'; isActive?: boolean }
|
|
>({
|
|
query: ({ id, role, isActive }) => ({
|
|
url: `/admin/users/${id}`,
|
|
method: 'PATCH',
|
|
body: {
|
|
is_superuser: role === undefined ? undefined : role === 'admin',
|
|
is_active: isActive,
|
|
},
|
|
}),
|
|
transformResponse: (raw: RawUser) => toUser(raw),
|
|
invalidatesTags: ['User'],
|
|
}),
|
|
deleteUser: build.mutation<void, string>({
|
|
query: (id) => ({ url: `/admin/users/${id}`, method: 'DELETE' }),
|
|
invalidatesTags: ['User'],
|
|
}),
|
|
}),
|
|
overrideExisting: false,
|
|
});
|
|
|
|
export const {
|
|
useGetUsersQuery,
|
|
useCreateUserMutation,
|
|
useUpdateUserMutation,
|
|
useDeleteUserMutation,
|
|
} = adminApi;
|