sign-in.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from "react";
  2. import Head from "next/head";
  3. import Link from "next/link";
  4. import { useRouter } from "next/router";
  5. import styled from "styled-components";
  6. import { Button, Center, Container, Stack } from "@mantine/core";
  7. import { AiOutlineGithub, AiOutlineGoogle } from "react-icons/ai";
  8. import { altogic } from "src/api/altogic";
  9. import { Footer } from "src/components/Footer";
  10. import { Navbar } from "src/components/Navbar";
  11. import useUser from "src/store/useUser";
  12. const StyledPageWrapper = styled.div`
  13. padding: 5%;
  14. `;
  15. const StyledHeroSection = styled.section`
  16. display: flex;
  17. justify-content: center;
  18. flex-direction: column;
  19. align-items: center;
  20. `;
  21. const SignIn = () => {
  22. const { isReady, replace } = useRouter();
  23. const checkSession = useUser(state => state.checkSession);
  24. const isAuthenticated = useUser(state => state.isAuthenticated);
  25. React.useEffect(() => {
  26. if (!isReady) checkSession();
  27. if (isAuthenticated) replace("/editor");
  28. }, [isReady, isAuthenticated, replace, checkSession]);
  29. const handleLoginClick = (provider: "github" | "google") => {
  30. altogic.auth.signInWithProvider(provider);
  31. };
  32. return (
  33. <>
  34. <Head>
  35. <title>Sign In | JSON Crack</title>
  36. </Head>
  37. <Navbar />
  38. <StyledPageWrapper>
  39. <StyledHeroSection>
  40. <Link href="/">
  41. <img src="assets/icon.png" alt="json crack" width="400" />
  42. </Link>
  43. <h1>Sign In</h1>
  44. </StyledHeroSection>
  45. <Container>
  46. <Center>
  47. <Stack my={60} w={250} spacing="xl">
  48. <Button
  49. size="md"
  50. color="red"
  51. onClick={() => handleLoginClick("google")}
  52. leftIcon={<AiOutlineGoogle size={24} />}
  53. >
  54. Sign In with Google
  55. </Button>
  56. <Button
  57. size="md"
  58. variant="white"
  59. color="gray"
  60. onClick={() => handleLoginClick("github")}
  61. leftIcon={<AiOutlineGithub size={24} />}
  62. >
  63. Sign In with GitHub
  64. </Button>
  65. </Stack>
  66. </Center>
  67. </Container>
  68. </StyledPageWrapper>
  69. <Footer />
  70. </>
  71. );
  72. };
  73. export default SignIn;