aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/OAuth2Button.tsx
blob: 231e5605fcbb9462033aa0a9dda8c074bf23ef95 (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
/** @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, { OAuthScopes } from "../api/auth";


interface OAuth2ButtonProps {
    scopes?: OAuthScopes[],
    path?: string
}

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);

    return (
        <button disabled={disabled} onClick={() => authenticate(props.scopes, setDisabled, props.path)}>
            <FontAwesomeIcon icon={faDiscord} css={iconStyles}/>
            <span css={textStyles}>Discord Login</span>
        </button>
    );
}

export default OAuth2Button;