useUser.tsx 761 B

1234567891011121314151617
  1. import configStore from 'sentry/stores/configStore';
  2. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  3. import type {User} from 'sentry/types';
  4. /**
  5. * Returns the currently logged in user.
  6. */
  7. export function useUser(): Readonly<User> {
  8. // Intentional exception to accessing the deprecated field as we want to
  9. // deter users from consuming the user differently than through the hook.
  10. const {user} = useLegacyStore(configStore);
  11. // @TODO: Return a readonly type as a mechanism to deter users from mutating the
  12. // user directly. That said, this provides basic type safety and no runtime safety
  13. // as there are still plenty of ways to mutate the user. The runtime safe way of
  14. // enforcing this would be via Object.freeze.
  15. return user;
  16. }