mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
6c5ab5414a
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.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
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 };
|
|
}
|