blob: 90a25fa540d151e25454a2d048ee526af5d54fcb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/** @jsx jsx */
import { css, jsx } from "@emotion/react";
import { useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faDiscord } from "@fortawesome/free-brands-svg-icons";
import authenticate, {checkScopes, OAuthScopes} from "../api/auth";
interface OAuth2ButtonProps {
scopes?: OAuthScopes[],
path?: string,
rerender: () => void
}
const iconStyles = css`
position: relative;
top: 0.3rem;
padding-left: 0.65rem;
font-size: 1.2em;
`;
const textStyles = css`
display: inline-block;
padding: 0.5rem 0.75rem 0.5rem 0.5rem;
`;
function OAuth2Button(props: OAuth2ButtonProps): JSX.Element {
const [disabled, setDisabled] = useState<boolean>(false);
async function login() {
await authenticate(props.scopes, setDisabled, props.path);
if (checkScopes(props.scopes, props.path)) {
props.rerender();
}
}
return (
<button disabled={disabled} onClick={() => login()}>
<FontAwesomeIcon icon={faDiscord} css={iconStyles}/>
<span css={textStyles}>Discord Login</span>
</button>
);
}
export default OAuth2Button;
|