diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index 36186ecac1..fb31fef380 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -22,11 +22,35 @@ type Account = Misskey.entities.MeDetailed & { token: string }; const accountData = miLocalStorage.getItem('account'); // TODO: 外部からはreadonlyに +/** + * Reactive state for the current account. "I" as in "I am logged in". + * Initialized from local storage if available, otherwise null. + * + * @type {Account | null} + */ export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : null; +/** + * Whether the current account is a moderator. + * + * @type {boolean} + */ export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true); + +/** + * Whether the current account is an administrator. + * + * @type {boolean} + */ export const iAmAdmin = $i != null && $i.isAdmin; +/** + * Whether it is necessary to sign in; checks if the current + * account is null and throws an error if so. + * + * @throws {Error} If the current account is null + * @returns {Account} The current account + */ export function signinRequired() { if ($i == null) throw new Error('signin required'); return $i;