Skip to content

Commit

Permalink
Hide option in UI for oAuth users
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal committed Jul 30, 2024
1 parent 214015c commit 969caf2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apps/meteor/client/views/account/security/TwoFactorEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Box, Button, Margins } from '@rocket.chat/fuselage';
import { useUser, useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps, ReactElement } from 'react';
import { useUser, useTranslation, useSetting } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React, { useCallback } from 'react';

import { useEndpointAction } from '../../../hooks/useEndpointAction';

const TwoFactorEmail = (props: ComponentProps<typeof Box>): ReactElement => {
const TwoFactorEmail = (props: ComponentProps<typeof Box>): JSX.Element | null => {
const t = useTranslation();
const user = useUser();

const disableEmail2FAForOAuth = useSetting('Accounts_TwoFactorAuthentication_Disable_Email_For_OAuth_Users');
const isOAuthUser = !user?.services?.password?.exists;
const isEnabled = user?.services?.email2fa?.enabled;
const isAllowed = !isOAuthUser || !disableEmail2FAForOAuth;

const enable2faAction = useEndpointAction('POST', '/v1/users.2fa.enableEmail', {
successMessage: t('Two-factor_authentication_enabled'),
Expand All @@ -25,6 +28,10 @@ const TwoFactorEmail = (props: ComponentProps<typeof Box>): ReactElement => {
await disable2faAction();
}, [disable2faAction]);

if (!isAllowed) {
return null;
}

return (
<Box display='flex' flexDirection='column' alignItems='flex-start' mbs={16} {...props}>
<Margins blockEnd={8}>
Expand Down

0 comments on commit 969caf2

Please sign in to comment.