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

[UI] EVEREST-1190 Display logged in user #1067

Merged
merged 9 commits into from
Feb 5, 2025
25 changes: 25 additions & 0 deletions ui/apps/everest/src/components/app-bar/user-icon/UserIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { useContext, useState } from 'react';
import {
Divider,
FormControlLabel,
FormGroup,
IconButton,
Menu,
MenuItem,
Switch,
Typography,
} from '@mui/material';
import PersonOutlineIcon from '@mui/icons-material/PersonOutline';
import { ColorModeContext } from '@percona/design';
import { AuthContext } from 'contexts/auth';
import { jwtDecode } from 'jwt-decode';

interface UserToken {
preferred_username?: string;
name?: string;
email?: string;
sub: string;
}

const AppBarUserIcon = () => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
Expand All @@ -23,6 +33,15 @@ const AppBarUserIcon = () => {
const handleClose = () => {
setAnchorEl(null);
};
const token = localStorage.getItem('everestToken');
const decoded = jwtDecode(token!) as UserToken;

const preferredUsername = decoded.preferred_username;
const name = decoded.name;
const email = decoded.email;
const sub = decoded.sub?.substring(0, decoded.sub.indexOf(':')) || '';
dianabirs marked this conversation as resolved.
Show resolved Hide resolved

const userToShow = preferredUsername || name || email || sub;

return (
<>
Expand All @@ -44,6 +63,12 @@ const AppBarUserIcon = () => {
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem sx={{ cursor: 'text', userSelect: 'text' }}>
<Typography variant="helperText" color="text.secondary">
{userToShow}
</Typography>
</MenuItem>
<Divider />
<MenuItem>
<FormGroup>
<FormControlLabel
Expand Down
Loading