F1Manager-Calc/components/LogIn.jsx

61 lines
1.8 KiB
React
Raw Normal View History

2023-04-17 20:50:24 +02:00
import { useSession, signIn, signOut } from "next-auth/react"
2023-04-18 14:14:23 +02:00
import {Avatar, Button, Chip, IconButton, Menu, MenuItem, Tooltip, Typography} from "@mui/material";
2023-04-17 20:50:24 +02:00
import {useState} from "react";
export default function LogIn() {
const { data: session } = useSession()
const [anchorElUser, setAnchorElUser] = useState(null);
if (session) {
return (
<div>
2023-04-18 14:14:23 +02:00
<Chip label="cloud sync on" color="primary"/>
2023-04-17 20:50:24 +02:00
<Tooltip title="Open settings">
2023-04-18 14:26:07 +02:00
<IconButton onClick={(event) => {
setAnchorElUser(event.currentTarget);
}} sx={{ p: 0, ml: 3 }}>
2023-04-17 20:50:24 +02:00
<Avatar alt={session.user.name} src={session.user.image} />
</IconButton>
</Tooltip>
<Menu
sx={{ mt: '45px' }}
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
open={Boolean(anchorElUser)}
2023-04-18 14:26:07 +02:00
onClose={() => {
setAnchorElUser(null)
}}
2023-04-17 20:50:24 +02:00
>
<MenuItem>
2023-04-18 09:51:22 +02:00
<Typography textAlign="center">Signed in as {session.user.name}#{session.user.discord_profile.discriminator}</Typography>
2023-04-17 20:50:24 +02:00
</MenuItem>
<MenuItem onClick={() => signOut()}>
<Typography textAlign="center">Log Out</Typography>
</MenuItem>
</Menu>
</div>
)
}
return (
<div>
2023-04-18 14:26:07 +02:00
<div>
<Button
variant="contained"
sx={{ ml: 3 }}
onClick={() => signIn("discord")}
>Discord Sign in</Button>
</div>
<div>
<Chip label="cloud sync disabled" color="default"/>
</div>
2023-04-17 20:50:24 +02:00
</div>
)
}