feat: add auth:read permission and ability to retrieve auth headers

This commit is contained in:
Niklas Voss
2026-04-01 11:26:12 +02:00
committed by Linus Rath
parent 58968a1cbf
commit 67a0d622bc
2 changed files with 17 additions and 1 deletions
+16
View File
@@ -25,6 +25,7 @@ import {
sidebarAppHooks,
} from './plugin-hooks';
import { toast as appToast } from '@/stores/toast-store';
import { useAuthStore } from '@/stores/auth-store';
// ─── Permission helpers ──────────────────────────────────────
@@ -128,6 +129,9 @@ export interface PluginAPI {
info: (message: string) => void;
warning: (message: string) => void;
};
auth: {
getHeaders: () => Record<string, string>;
};
storage: ReturnType<typeof createPluginStorage>;
log: ReturnType<typeof createPluginLogger>;
admin: {
@@ -640,6 +644,18 @@ export function createPluginAPI(plugin: InstalledPlugin): PluginAPI {
warning: (message: string) => appToast.warning(message),
},
auth: {
getHeaders: (): Record<string, string> => {
requirePermission(plugin, 'auth:read');
const { client } = useAuthStore.getState();
if (!client) return {};
return {
'Authorization': client.getAuthHeader(),
'X-JMAP-Username': client.getUsername(),
};
},
},
storage: createPluginStorage(plugin.id),
log: createPluginLogger(plugin.id),