Files
mdm-ordinis/ordinis-admin-ui/src/auth/useCanMutate.ts
T
2026-05-10 19:34:47 +00:00

20 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useAuth } from 'react-oidc-context'
/**
* Может ли текущий пользователь выполнять mutation операции (create / update /
* delete / close / cascade).
*
* <p>Гость (anonymous) видит UI в read-only режиме: кнопки «Создать», «Удалить»,
* иконки edit'а скрыты, schema editor disabled. Backend всё равно отрежет 401
* на mutation endpoint'ах (writer требует JWT для POST/PUT/PATCH/DELETE), но
* скрытие UI избегает confusing user experience «жмёшь кнопку → toast 401».
*
* <p>Использовать в компонентах вместо прямого {@code useAuth().isAuthenticated},
* чтобы при будущей более тонкой role-based gate'е (например, разрешить
* INTERNAL юзерам только PUBLIC mutations) — поменять одно место.
*/
export function useCanMutate(): boolean {
const auth = useAuth()
return auth.isAuthenticated
}