Skip to content

Commit

Permalink
Update Login.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
dobri1408 authored Oct 11, 2024
1 parent 5245cda commit 3efac9e
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions packages/volto/src/components/theme/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ import {
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
import qs from 'query-string';

import { Helmet } from '@plone/volto/helpers';
import { Helmet, usePrevious } from '@plone/volto/helpers';
import config from '@plone/volto/registry';
import { Icon } from '@plone/volto/components';
import { login, resetLoginRequest } from '@plone/volto/actions';
import {
login,
logout,
resetLoginRequest,
purgeMessages,
} from '@plone/volto/actions';
import { toast } from 'react-toastify';
import { Toast } from '@plone/volto/components';
import aheadSVG from '@plone/volto/icons/ahead.svg';
Expand Down Expand Up @@ -77,11 +82,22 @@ const Login = (props) => {
qs.parse(props.location?.search ?? location.search).return_url ||
location.pathname.replace(/\/[^\/]*\/?$/, '') || '/';

Check warning on line 83 in packages/volto/src/components/theme/Login/Login.jsx

View workflow job for this annotation

GitHub Actions / ESlint

Unnecessary escape character: \/

Check failure on line 83 in packages/volto/src/components/theme/Login/Login.jsx

View workflow job for this annotation

GitHub Actions / ESlint

Insert `⏎···`

const previousToken = usePrevious(token);

useEffect(() => {
console.log(returnUrl)
if (token && !(props.isLogout || location?.state?.isLogout)) {

if (location?.state?.isLogout) {
// Execute a true Logout action
// This is needed to cover the use case of being logged in in
// another backend (eg. in development), having a token for
// localhost and try to use it, the login route has to know that
// it's the same as it comes from a logout
// See also Unauthorized.jsx
dispatch(logout());
dispatch(purgeMessages());
// Reset the location state
history.push(`${location.pathname}${location.search}`);
} else if (token && token !== previousToken) {
// We just did a true login action
history.push(returnUrl || '/');
if (toast.isActive('loggedOut')) {
toast.dismiss('loggedOut');
Expand Down Expand Up @@ -118,8 +134,10 @@ const Login = (props) => {
intl,
history,
returnUrl,
props.isLogout,
location.search,
location.pathname,
location?.state?.isLogout,
previousToken,
]);

const onLogin = (event) => {
Expand Down

0 comments on commit 3efac9e

Please sign in to comment.