A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(app): prompt for sudo when the API asks for it
Hampus6a28f287e7d5
diff --git a/fluxer_app/src/features/auth/hooks/useSudo.ts b/fluxer_app/src/features/auth/hooks/useSudo.tsdeleted file mode 100644index d0692bed9..000000000--- a/fluxer_app/src/features/auth/hooks/useSudo.ts+++ /dev/null@@ -1,19 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-or-later--import Sudo from '@app/features/auth/state/AuthSudo';-import SudoPrompt from '@app/features/auth/state/SudoPrompt';-import type {SudoVerificationPayload} from '@app/features/auth/types/AuthSudoTypes';-import {useCallback} from 'react';--export function useSudo() {- const require = useCallback(async (): Promise<SudoVerificationPayload> => {- if (Sudo.hasValidToken()) {- return {};- }- return await SudoPrompt.requestVerification();- }, []);- const finalize = useCallback(() => {- SudoPrompt.handleTokenReceived(null);- }, []);- return {require, finalize};-}diff --git a/fluxer_app/src/features/user/commands/UserCommands.ts b/fluxer_app/src/features/user/commands/UserCommands.tsindex e70458aa2..703b72929 100644--- a/fluxer_app/src/features/user/commands/UserCommands.ts+++ b/fluxer_app/src/features/user/commands/UserCommands.ts@@ -3,8 +3,6 @@import {Endpoints} from '@app/features/app/constants/Endpoints';import AuthSession from '@app/features/auth/state/AuthSession';import Sudo from '@app/features/auth/state/AuthSudo';-import SudoPrompt from '@app/features/auth/state/SudoPrompt';-import type {SudoVerificationPayload} from '@app/features/auth/types/AuthSudoTypes';import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';import Messages from '@app/features/messaging/state/MessagingMessages';import SessionManager from '@app/features/platform/state/AuthSession';@@ -325,21 +323,16 @@ export async function deleteAccount(): Promise<void> {logger.info('Account scheduled for deletion');}-export async function forgetAuthorizedIps(sudoPayload: SudoVerificationPayload): Promise<void> {+export async function forgetAuthorizedIps(): Promise<void> {logger.debug('Forgetting authorized IPs');- await http.delete(Endpoints.USER_AUTHORIZED_IPS, {body: sudoPayload});+ await http.delete(Endpoints.USER_AUTHORIZED_IPS, {body: {}});logger.info('Authorised IPs cleared');}export async function bulkDeleteMyMessages(filter: BulkDeleteMyMessagesFilter): Promise<void> {logger.debug('Requesting bulk deletion of my messages', filter);await http.post(Endpoints.USER_BULK_DELETE_MY_MESSAGES, {- body: {- ...filter,- ...(Sudo.hasValidToken()- ? {}- : await SudoPrompt.requestVerification({method: 'POST', path: Endpoints.USER_BULK_DELETE_MY_MESSAGES})),- },+ body: filter,});logger.info('Bulk message deletion queued');}diff --git a/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationDetail.tsx b/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationDetail.tsxindex 0f488312a..2c4d0135b 100644--- a/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationDetail.tsx+++ b/fluxer_app/src/features/user/components/modals/tabs/applications_tab/ApplicationDetail.tsx@@ -5,7 +5,6 @@ import {StatusSlate} from '@app/features/app/components/dialogs/shared/StatusSlaimport {Endpoints} from '@app/features/app/constants/Endpoints';import {useFormSubmit} from '@app/features/app/hooks/useFormSubmit';import RuntimeConfig from '@app/features/app/state/RuntimeConfig';-import {useSudo} from '@app/features/auth/hooks/useSudo';import type {DeveloperApplication} from '@app/features/devtools/models/DeveloperApplication';import {TRY_AGAIN_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import {formatBotPermissionsQuery, getAllBotPermissions} from '@app/features/permissions/utils/PermissionUtils';@@ -125,7 +124,6 @@ export const ApplicationDetail: React.FC<ApplicationDetailProps> = observer(const [isRotating, setIsRotating] = useState<'client' | 'bot' | null>(null);const clientSecretInputId = useId();const botTokenInputId = useId();- const sudo = useSudo();const form = useForm<ApplicationDetailFormValues>({defaultValues: {name: '',@@ -441,18 +439,16 @@ export const ApplicationDetail: React.FC<ApplicationDetailProps> = observer(if (!application) return;setIsRotating(type);try {- const sudoPayload = await sudo.require();const endpoint =type === 'client'? Endpoints.OAUTH_APPLICATION_CLIENT_SECRET_RESET(application.id): Endpoints.OAUTH_APPLICATION_BOT_TOKEN_RESET(application.id);- const res = await http.post<{client_secret?: string; token?: string}>(endpoint, {body: sudoPayload});+ const res = await http.post<{client_secret?: string; token?: string}>(endpoint, {body: {}});if (type === 'client') {setClientSecret(res.body.client_secret ?? null);} else {setBotToken(res.body.token ?? null);}- sudo.finalize();ToastCommands.createToast({type: 'success',children:@@ -607,13 +603,11 @@ export const ApplicationDetail: React.FC<ApplicationDetailProps> = observer(: null;const displayAvatarUrl = hasClearedAvatar ? defaultAvatarUrl : previewAvatarUrl || avatarUrl || defaultAvatarUrl;const hasAvatar = (!hasClearedAvatar && Boolean(application.bot?.avatar)) || Boolean(previewAvatarUrl);- const displayBannerUrl =- previewBannerUrl ||- (hasClearedBanner- ? null- : application.bot- ? AvatarUtils.getUserBannerURL({id: application.bot.id, banner: application.bot.banner}, true)- : null);+ const botBannerUrl =+ !hasClearedBanner && application.bot+ ? AvatarUtils.getUserBannerURL({id: application.bot.id, banner: application.bot.banner}, true)+ : null;+ const displayBannerUrl = previewBannerUrl || botBannerUrl;const hasBanner = Boolean(displayBannerUrl || bannerValue);return (<Form form={form} onSubmit={onSubmit} data-flx="user.applications-tab.application-detail.form.submit">