Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove simultaneous logins #528

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export const DEFAULT_FEATURES = {
watchListSizeLimit: MAX_WATCHLIST_ITEMS_COUNT,
};

export const simultaneousLoginWarningKey = 'simultaneous_logins';

export const EPG_TYPE = {
jwp: 'jwp',
viewNexa: 'viewnexa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('<LoginForm>', () => {
errors={{}}
socialLoginURLs={socialLoginURLs}
submitting={false}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand All @@ -62,7 +61,6 @@ describe('<LoginForm>', () => {
errors={{}}
socialLoginURLs={null}
submitting={false}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand All @@ -85,7 +83,6 @@ describe('<LoginForm>', () => {
errors={{ email: 'Email error', password: 'Password error', form: 'Form error' }}
socialLoginURLs={null}
submitting={false}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand All @@ -109,7 +106,6 @@ describe('<LoginForm>', () => {
errors={{}}
socialLoginURLs={null}
submitting={true}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand All @@ -133,7 +129,6 @@ describe('<LoginForm>', () => {
errors={{}}
socialLoginURLs={null}
submitting={true}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand Down Expand Up @@ -161,7 +156,6 @@ describe('<LoginForm>', () => {
errors={{}}
socialLoginURLs={null}
submitting={true}
messageKey={null}
/>,
{ wrapper: createWrapper() },
);
Expand Down
17 changes: 1 addition & 16 deletions packages/ui-react/src/components/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { LoginFormData } from '@jwp/ott-common/types/account';
import { testId } from '@jwp/ott-common/src/utils/common';
import useToggle from '@jwp/ott-hooks-react/src/useToggle';
import type { SocialLoginURLs } from '@jwp/ott-hooks-react/src/useSocialLoginUrls';
import { simultaneousLoginWarningKey } from '@jwp/ott-common/src/constants';
import Visibility from '@jwp/ott-theme/assets/icons/visibility.svg?react';
import VisibilityOff from '@jwp/ott-theme/assets/icons/visibility_off.svg?react';

Expand All @@ -32,29 +31,15 @@ type Props = {
submitting: boolean;
socialLoginURLs: SocialLoginURLs | null;
siteName?: string;
messageKey: string | null;
};

const LoginForm: React.FC<Props> = ({ onSubmit, onChange, socialLoginURLs, values, errors, validationError, submitting, siteName, messageKey }: Props) => {
const LoginForm: React.FC<Props> = ({ onSubmit, onChange, socialLoginURLs, values, errors, validationError, submitting, siteName }: Props) => {
const [viewPassword, toggleViewPassword] = useToggle();
const { t } = useTranslation('account');
const location = useLocation();

const getTranslatedErrorMessage = (messageId: string | null) => {
switch (messageId) {
case simultaneousLoginWarningKey:
return t('login.simultaneous_logins');
}
return t('login.unexpected_error');
};

return (
<form onSubmit={onSubmit} data-testid={testId('login-form')} noValidate>
{messageKey && (
<div className={styles.top}>
<FormFeedback variant="warning">{getTranslatedErrorMessage(messageKey)}</FormFeedback>
</div>
)}
{errors.form ? (
<FormFeedback variant="error" visible={!validationError}>
{errors.form}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Login from './forms/Login';
import styles from './AccountModal.module.scss';

// @todo: connect with route typings
const PUBLIC_VIEWS = ['login', 'create-account', 'forgot-password', 'reset-password', 'send-confirmation', 'edit-password', 'simultaneous-logins'];
const PUBLIC_VIEWS = ['login', 'create-account', 'forgot-password', 'reset-password', 'send-confirmation', 'edit-password'];

export type AccountModals = {
login: 'login';
Expand Down Expand Up @@ -108,7 +108,7 @@ const AccountModal = () => {

switch (view) {
case 'login':
return <Login messageKey={message} />;
return <Login />;
case 'create-account':
return <Registration />;
case 'personal-details':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import type { LoginFormData } from '@jwp/ott-common/types/account';
import LoginForm from '../../../components/LoginForm/LoginForm';
import { useAriaAnnouncer } from '../../AnnouncementProvider/AnnoucementProvider';

type Props = {
messageKey: string | null;
};

const Login: React.FC<Props> = ({ messageKey }: Props) => {
const Login = () => {
const accountController = getModule(AccountController);

const { siteName } = useConfigStore((s) => s.config);
Expand Down Expand Up @@ -53,7 +49,6 @@ const Login: React.FC<Props> = ({ messageKey }: Props) => {
submitting={submitting}
siteName={siteName}
socialLoginURLs={socialLoginURLs}
messageKey={messageKey}
onSubmit={handleSubmit}
onChange={handleChange}
/>
Expand Down
1 change: 0 additions & 1 deletion platforms/web/public/locales/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"sign_in": "Sign in",
"sign_in_success": "Sign in successful",
"sign_up": "Sign up",
"simultaneous_logins": "The maximum number of active sessions for this account has been reached. Signing in here will sign you out from another session or device.",
"twitter": "Sign in with Twitter",
"unexpected_error": "An unexpected error occurred.",
"view_password": "View password",
Expand Down
1 change: 0 additions & 1 deletion platforms/web/public/locales/es/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"sign_in": "Iniciar sesión",
"sign_in_success": "Has iniciado sesión correctamente.",
"sign_up": "Registrarse",
"simultaneous_logins": "Se ha alcanzado el número máximo de sesiones activas para esta cuenta. Iniciar sesión aquí lo cerrará en otra sesión o dispositivo.",
"twitter": "Inicia sesión con Twitter",
"unexpected_error": "Ocurrió un error inesperado.",
"view_password": "Ver contraseña",
Expand Down
10 changes: 0 additions & 10 deletions platforms/web/src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useLocation, useNavigate } from 'react-router';
import { getModule } from '@jwp/ott-common/src/modules/container';
import AccountController from '@jwp/ott-common/src/controllers/AccountController';
import { queryClient } from '@jwp/ott-ui-react/src/containers/QueryProvider/QueryProvider';
import { simultaneousLoginWarningKey } from '@jwp/ott-common/src/constants';
import { modalURLFromLocation } from '@jwp/ott-ui-react/src/utils/location';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import useEventCallback from '@jwp/ott-hooks-react/src/useEventCallback';
Expand Down Expand Up @@ -63,15 +62,6 @@ export default function useNotifications() {
case NotificationsTypes.SUBSCRIBE_REQUIRES_ACTION:
window.location.href = notification.resource?.redirect_to_url;
break;
case NotificationsTypes.ACCOUNT_LOGOUT:
try {
await accountController?.logout();
} finally {
if (notification.resource?.reason === 'sessions_limit') {
navigateToModal('login', { message: simultaneousLoginWarningKey });
}
}
break;
default:
break;
}
Expand Down
Loading