import { useState , useEffect } from 'react' ; import { useKibana } from '../../../../../src/plugins/kibana_react/public' ; import { ApmPluginStartDeps } from '../plugin' ; import { AuthenticatedUser } from '../../../security/common/model' ; export function useCurrentUser ( ) { const { services : { security } , } = useKibana < ApmPluginStartDeps > ( ) ; const [ user , setUser ] = useState < AuthenticatedUser > ( ) ; useEffect ( ( ) => { const getCurrentUser = async ( ) => { try { const authenticatedUser = await security ?. authc . getCurrentUser ( ) ; setUser ( authenticatedUser ) ; } catch { setUser ( undefined ) ; } } ; getCurrentUser ( ) ; } , [ security ?. authc ] ) ; return user ; }