mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 16:22:10 +00:00
Add logout event to audit logs
This commit is contained in:
parent
d8ae7ad98b
commit
70e88d2891
@ -2,7 +2,7 @@ import React, { useRef, useState } from 'react';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { NavLink as RouterNavLink, useLocation } from 'react-router-dom';
|
import { NavLink as RouterNavLink, useLocation, useHistory } from 'react-router-dom';
|
||||||
import { Divider } from '@strapi/design-system/Divider';
|
import { Divider } from '@strapi/design-system/Divider';
|
||||||
import {
|
import {
|
||||||
MainNav,
|
MainNav,
|
||||||
@ -20,7 +20,8 @@ import { Stack } from '@strapi/design-system/Stack';
|
|||||||
import Write from '@strapi/icons/Write';
|
import Write from '@strapi/icons/Write';
|
||||||
import Exit from '@strapi/icons/Exit';
|
import Exit from '@strapi/icons/Exit';
|
||||||
import { auth, usePersistentState, useAppInfos, useTracking } from '@strapi/helper-plugin';
|
import { auth, usePersistentState, useAppInfos, useTracking } from '@strapi/helper-plugin';
|
||||||
import useConfigurations from '../../hooks/useConfigurations';
|
import { useConfigurations } from '../../hooks';
|
||||||
|
import { axiosInstance } from '../../core/utils';
|
||||||
|
|
||||||
const LinkUserWrapper = styled(Box)`
|
const LinkUserWrapper = styled(Box)`
|
||||||
width: ${150 / 16}rem;
|
width: ${150 / 16}rem;
|
||||||
@ -61,6 +62,7 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const initials = userDisplayName
|
const initials = userDisplayName
|
||||||
.split(' ')
|
.split(' ')
|
||||||
@ -70,9 +72,11 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
|||||||
|
|
||||||
const handleToggleUserLinks = () => setUserLinksVisible((prev) => !prev);
|
const handleToggleUserLinks = () => setUserLinksVisible((prev) => !prev);
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = async () => {
|
||||||
|
await axiosInstance.post('/admin/logout');
|
||||||
auth.clearAppStorage();
|
auth.clearAppStorage();
|
||||||
handleToggleUserLinks();
|
handleToggleUserLinks();
|
||||||
|
history.push('/auth/login');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBlur = (e) => {
|
const handleBlur = (e) => {
|
||||||
@ -205,7 +209,7 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
|||||||
})}
|
})}
|
||||||
</Typography>
|
</Typography>
|
||||||
</LinkUser>
|
</LinkUser>
|
||||||
<LinkUser tabIndex={0} onClick={handleLogout} logout="logout" to="/auth/login">
|
<LinkUser as="button" tabIndex={0} onClick={handleLogout} logout="logout">
|
||||||
<Typography textColor="danger600">
|
<Typography textColor="danger600">
|
||||||
{formatMessage({
|
{formatMessage({
|
||||||
id: 'app.components.LeftMenu.logout',
|
id: 'app.components.LeftMenu.logout',
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const defaultEvents = [
|
|||||||
'user.update',
|
'user.update',
|
||||||
'user.delete',
|
'user.delete',
|
||||||
'admin.auth.success',
|
'admin.auth.success',
|
||||||
|
'admin.logout',
|
||||||
];
|
];
|
||||||
|
|
||||||
const getEventMap = (defaultEvents) => {
|
const getEventMap = (defaultEvents) => {
|
||||||
|
|||||||
@ -157,4 +157,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
logout(ctx) {
|
||||||
|
const sanitizedUser = getService('user').sanitizeUser(ctx.state.user);
|
||||||
|
strapi.eventHub.emit('admin.logout', { user: sanitizedUser });
|
||||||
|
ctx.body = { data: {} };
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -43,4 +43,12 @@ module.exports = [
|
|||||||
handler: 'authentication.resetPassword',
|
handler: 'authentication.resetPassword',
|
||||||
config: { auth: false },
|
config: { auth: false },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
path: '/logout',
|
||||||
|
handler: 'authentication.logout',
|
||||||
|
config: {
|
||||||
|
policies: ['admin::isAuthenticatedAdmin'],
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user