mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +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 PropTypes from 'prop-types';
|
||||
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 {
|
||||
MainNav,
|
||||
@ -20,7 +20,8 @@ import { Stack } from '@strapi/design-system/Stack';
|
||||
import Write from '@strapi/icons/Write';
|
||||
import Exit from '@strapi/icons/Exit';
|
||||
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)`
|
||||
width: ${150 / 16}rem;
|
||||
@ -61,6 +62,7 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { trackUsage } = useTracking();
|
||||
const { pathname } = useLocation();
|
||||
const history = useHistory();
|
||||
|
||||
const initials = userDisplayName
|
||||
.split(' ')
|
||||
@ -70,9 +72,11 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
||||
|
||||
const handleToggleUserLinks = () => setUserLinksVisible((prev) => !prev);
|
||||
|
||||
const handleLogout = () => {
|
||||
const handleLogout = async () => {
|
||||
await axiosInstance.post('/admin/logout');
|
||||
auth.clearAppStorage();
|
||||
handleToggleUserLinks();
|
||||
history.push('/auth/login');
|
||||
};
|
||||
|
||||
const handleBlur = (e) => {
|
||||
@ -205,7 +209,7 @@ const LeftMenu = ({ generalSectionLinks, pluginsSectionLinks }) => {
|
||||
})}
|
||||
</Typography>
|
||||
</LinkUser>
|
||||
<LinkUser tabIndex={0} onClick={handleLogout} logout="logout" to="/auth/login">
|
||||
<LinkUser as="button" tabIndex={0} onClick={handleLogout} logout="logout">
|
||||
<Typography textColor="danger600">
|
||||
{formatMessage({
|
||||
id: 'app.components.LeftMenu.logout',
|
||||
|
||||
@ -13,6 +13,7 @@ const defaultEvents = [
|
||||
'user.update',
|
||||
'user.delete',
|
||||
'admin.auth.success',
|
||||
'admin.logout',
|
||||
];
|
||||
|
||||
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',
|
||||
config: { auth: false },
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/logout',
|
||||
handler: 'authentication.logout',
|
||||
config: {
|
||||
policies: ['admin::isAuthenticatedAdmin'],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user