mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
add isAdmin to auth state
This commit is contained in:
@@ -91,6 +91,7 @@ export const JellyfinController: InternalControllerEndpoint = {
|
||||
|
||||
return {
|
||||
credential: res.body.AccessToken,
|
||||
isAdmin: Boolean(res.body.User.Policy.IsAdministrator),
|
||||
userId: res.body.User.Id,
|
||||
username: res.body.User.Name,
|
||||
};
|
||||
|
||||
@@ -131,6 +131,7 @@ export const NavidromeController: InternalControllerEndpoint = {
|
||||
|
||||
return {
|
||||
credential: `u=${body.username}&s=${res.body.data.subsonicSalt}&t=${res.body.data.subsonicToken}`,
|
||||
isAdmin: Boolean(res.body.data.isAdmin),
|
||||
ndCredential: res.body.data.token,
|
||||
userId: res.body.data.id,
|
||||
username: res.body.data.username,
|
||||
|
||||
@@ -16,7 +16,7 @@ const c = initContract();
|
||||
export const contract = c.router({
|
||||
authenticate: {
|
||||
method: 'GET',
|
||||
path: 'ping.view',
|
||||
path: 'getUser.view',
|
||||
query: ssType._parameters.authenticate,
|
||||
responses: {
|
||||
200: ssType._response.authenticate,
|
||||
|
||||
@@ -132,6 +132,7 @@ export const SubsonicController: InternalControllerEndpoint = {
|
||||
query: {
|
||||
c: 'Feishin',
|
||||
f: 'json',
|
||||
username: body.username,
|
||||
v: '1.13.0',
|
||||
...credentialParams,
|
||||
},
|
||||
@@ -143,7 +144,8 @@ export const SubsonicController: InternalControllerEndpoint = {
|
||||
|
||||
return {
|
||||
credential,
|
||||
userId: null,
|
||||
isAdmin: resp.body.user.adminRoles,
|
||||
userId: resp.body.user.username,
|
||||
username: body.username,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -140,6 +140,7 @@ const LoginRoute = () => {
|
||||
const serverItem: ServerListItemWithCredential = {
|
||||
credential: data.credential,
|
||||
id: nanoid(),
|
||||
isAdmin: data.isAdmin,
|
||||
name: serverName,
|
||||
type: serverType as ServerType,
|
||||
url: serverUrl.replace(/\/$/, ''),
|
||||
|
||||
@@ -156,6 +156,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
|
||||
const serverItem: ServerListItemWithCredential = {
|
||||
credential: data.credential,
|
||||
id: nanoid(),
|
||||
isAdmin: data.isAdmin,
|
||||
name: values.name,
|
||||
type: values.type as ServerType,
|
||||
url: values.url.replace(/\/$/, ''),
|
||||
|
||||
@@ -50,6 +50,7 @@ export const EditServerForm = ({ isUpdate, onCancel, password, server }: EditSer
|
||||
|
||||
const form = useForm({
|
||||
initialValues: {
|
||||
isAdmin: server?.isAdmin,
|
||||
legacyAuth: false,
|
||||
name: server?.name,
|
||||
password: password || '',
|
||||
@@ -94,6 +95,7 @@ export const EditServerForm = ({ isUpdate, onCancel, password, server }: EditSer
|
||||
const serverItem: ServerListItemWithCredential = {
|
||||
credential: data.credential,
|
||||
id: server.id,
|
||||
isAdmin: data.isAdmin,
|
||||
name: values.name,
|
||||
type: values.type,
|
||||
url: values.url,
|
||||
|
||||
@@ -120,6 +120,7 @@ export const useCurrentServer = () =>
|
||||
return {
|
||||
features: state.currentServer?.features,
|
||||
id: state.currentServer?.id,
|
||||
isAdmin: state.currentServer?.isAdmin,
|
||||
musicFolderId: state.currentServer?.musicFolderId,
|
||||
name: state.currentServer?.name,
|
||||
preferInstantMix: state.currentServer?.preferInstantMix,
|
||||
@@ -132,6 +133,14 @@ export const useCurrentServer = () =>
|
||||
};
|
||||
}, shallow) as ServerListItem;
|
||||
|
||||
export const useIsAdmin = () =>
|
||||
useAuthStore((state) => {
|
||||
return {
|
||||
isAdmin: state.currentServer?.isAdmin ?? false,
|
||||
userId: state.currentServer?.userId,
|
||||
};
|
||||
}, shallow);
|
||||
|
||||
export const useCurrentServerWithCredential = () =>
|
||||
useAuthStore((state) => state.currentServer) as ServerListItemWithCredential;
|
||||
|
||||
@@ -146,3 +155,14 @@ export const getServerById = (id?: string) => {
|
||||
|
||||
return useAuthStore.getState().actions.getServer(id);
|
||||
};
|
||||
|
||||
export const usePermissions = () => {
|
||||
const { isAdmin, userId } = useIsAdmin();
|
||||
|
||||
return {
|
||||
playlists: {
|
||||
editPublic: isAdmin,
|
||||
},
|
||||
userId: userId,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -7,7 +7,24 @@ const baseResponse = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
const authenticate = z.null();
|
||||
const authenticate = z.object({
|
||||
user: z.object({
|
||||
adminRoles: z.boolean(),
|
||||
commentRole: z.boolean(),
|
||||
coverArtRole: z.boolean(),
|
||||
downloadRole: z.boolean(),
|
||||
folder: z.string().array(),
|
||||
jukeboxRole: z.boolean(),
|
||||
playlistRole: z.boolean(),
|
||||
podcastRole: z.boolean(),
|
||||
scrobblingEnabled: z.boolean(),
|
||||
settingsRole: z.boolean(),
|
||||
shareRole: z.boolean(),
|
||||
streamRole: z.boolean(),
|
||||
uploadRole: z.boolean(),
|
||||
username: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
const authenticateParameters = z.object({
|
||||
c: z.string(),
|
||||
@@ -16,6 +33,7 @@ const authenticateParameters = z.object({
|
||||
s: z.string().optional(),
|
||||
t: z.string().optional(),
|
||||
u: z.string(),
|
||||
username: z.string(),
|
||||
v: z.string(),
|
||||
});
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ export type QueueSong = Song & {
|
||||
export type ServerListItem = {
|
||||
features?: ServerFeatures;
|
||||
id: string;
|
||||
isAdmin?: boolean;
|
||||
musicFolderId?: string[];
|
||||
name: string;
|
||||
preferInstantMix?: boolean;
|
||||
@@ -237,6 +238,7 @@ export type Artist = {
|
||||
|
||||
export type AuthenticationResponse = {
|
||||
credential: string;
|
||||
isAdmin?: boolean;
|
||||
ndCredential?: string;
|
||||
userId: null | string;
|
||||
username: string;
|
||||
|
||||
Reference in New Issue
Block a user