mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 16:13:15 +00:00
The top bar replaces the navigation rail on desktop, and with it went the shield that takes a Stalwart admin to the console, so an admin under Mountain View had no way in. The bar now shows it, with the same update dot. The check that decides it moves out of the rail into useStalwartAdmin so both use the same one.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { getActiveAccountSlotHeaders } from "@/lib/auth/active-account-slot";
|
|
import { apiFetch } from "@/lib/browser-navigation";
|
|
import { IS_LITE } from "@/lib/lite";
|
|
|
|
/**
|
|
* Whether the signed-in user may open the Stalwart admin console. In "auto"
|
|
* mode the admin session is minted here as well, so /admin works even after a
|
|
* full page navigation; in "password" mode the console asks for it (#870).
|
|
*/
|
|
export function useStalwartAdmin(): boolean {
|
|
const [isStalwartAdmin, setIsStalwartAdmin] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
const headers = getActiveAccountSlotHeaders();
|
|
// No admin console in the static Lite build.
|
|
if (IS_LITE || !headers['X-JMAP-Cookie-Slot']) return;
|
|
apiFetch('/api/admin/auth', { headers })
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
if (cancelled || !data.stalwartAdmin) return;
|
|
setIsStalwartAdmin(true);
|
|
if (!data.authenticated && data.stalwartAutoLogin === true) {
|
|
apiFetch('/api/admin/auth', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...headers },
|
|
body: JSON.stringify({ stalwartAuth: true }),
|
|
}).catch(() => {});
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
return () => { cancelled = true; };
|
|
}, []);
|
|
|
|
return isStalwartAdmin;
|
|
}
|