import { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from "@mui/material"; import { Check, Close } from '@mui/icons-material' import React from "react"; import { messageChannelContext } from "../provider/MessageChannel"; import Require from "./Require"; import { useSnackbar } from "notistack"; const AuthButton: React.FC = () => { const snackbar = useSnackbar(); const [open, setOpen] = React.useState(false); const [username, setUsername] = React.useState(''); const [password, setPassword] = React.useState(''); const [usernameError, setUsernameError] = React.useState(false); const [passwordError, setPasswordError] = React.useState(false); const messageChannel = React.useContext(messageChannelContext); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState(undefined); const [authed, setAuthed] = React.useState(false); const checkAuth = async () => { setAuthed((await messageChannel?.checkToken())?.isOk ?? false); } React.useEffect(() => { checkAuth() }, []); const handleSubmit = async () => { if (!messageChannel) throw new Error('Invalid state'); //The components to confirm only render if the messageChannel is not undefinded if (username.trim().length === 0) return setUsernameError(true); if (password.trim().length === 0) return setPasswordError(true); setUsernameError(false); setPasswordError(false); setLoading(true); const res = await messageChannel.auth({ username, password }); if (res.isOk) { setOpen(false); snackbar.enqueueSnackbar('Logged in', { variant: 'success' }); setUsername(''); setPassword(''); } else { setError(res.reason); } await checkAuth(); setLoading(false); } return Error during Authentication {error?.name} {error?.message} Authentication Here, you need to enter your username (most likely your Email) and your password.
These information are not stored anywhere and are only used to authenticate with the service once.
setUsername(e.target.value)} disabled={loading} /> setPassword(e.target.value)} disabled={loading} />
{loading && }
} export default AuthButton;