refactor(admin): share the JWT rotation and passkey reset between desktop and phone

useAdminUserActions now rotates the JWT secret and resets a user's passkeys for the desktop dialogs and the phone sheets. Each shell keeps its own confirm step, and the phone sheet still stays busy until the reset settles.
This commit is contained in:
Maurice
2026-10-09 11:00:21 +02:00
parent feb99ce398
commit 6c5ab5414a
4 changed files with 139 additions and 44 deletions
@@ -0,0 +1,46 @@
import { adminApi } from '../../api/client';
import type { TranslationFn } from '../../types';
interface UserActionsHost {
toast: { success: (message: string) => void; error: (message: string) => void };
setRotatingJwt: (value: boolean) => void;
setShowRotateJwtModal: (value: boolean) => void;
logout: () => void;
navigate: (to: string, options?: { state?: unknown }) => void;
}
/**
* The two irreversible user actions behind the admin dialogs and their phone sheets:
* rotating the JWT secret, which signs everyone out including the admin, and removing a
* user's passkeys. Each shell keeps its own confirm step and busy state around them.
*/
export function useAdminUserActions(admin: UserActionsHost, t: TranslationFn) {
const { toast, setRotatingJwt, setShowRotateJwtModal, logout, navigate } = admin;
const rotateJwt = async () => {
setRotatingJwt(true);
try {
await adminApi.rotateJwtSecret();
setShowRotateJwtModal(false);
logout();
navigate('/login', { state: { noRedirect: true } });
} catch {
toast.error(t('common.error'));
setRotatingJwt(false);
}
};
/** Removes the user's passkeys and toasts how many went; true when it worked. */
const resetPasskeys = async (user: { id: number }): Promise<boolean> => {
try {
const r = await adminApi.resetUserPasskeys(user.id);
toast.success(t('admin.passkey.resetDone', { count: r.deleted ?? 0 }));
return true;
} catch {
toast.error(t('common.error'));
return false;
}
};
return { rotateJwt, resetPasskeys };
}