-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3865ff3
commit 492edff
Showing
1 changed file
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { Box, Button, PageLayout } from "@primer/react"; | ||
import { Box, Button, PageLayout, Spinner } from "@primer/react"; | ||
import { useNavigate } from "react-router"; | ||
import { GoogleLogin } from "@react-oauth/google"; | ||
import { useState } from "react"; | ||
import TopNav from "../TopNav/TopNav"; | ||
import { authenticationService } from "../../services/authentication"; | ||
import { isProduction } from "../../constants"; | ||
import { jwtDecode } from "jwt-decode"; | ||
|
||
function Login() { | ||
const navigate = useNavigate(); | ||
const [isLoggingIn, setIsLoggingIn] = useState(false); | ||
|
||
function productionLoginHandler(response) { | ||
setIsLoggingIn(true); | ||
const user = jwtDecode(response.credential); | ||
if (authenticationService.isValidUser(user)) { | ||
authenticationService.setUser(user); | ||
|
@@ -20,24 +23,28 @@ function Login() { | |
} | ||
|
||
function developmentLoginHandler() { | ||
setIsLoggingIn(true); | ||
authenticationService.setUser({ | ||
name: "Test", | ||
given_name: "Test", | ||
email: "[email protected]", | ||
}); | ||
navigate("/"); | ||
setTimeout(() => { | ||
navigate("/"); | ||
}, 1000); | ||
} | ||
|
||
const loginButton = isProduction() ? ( | ||
<GoogleLogin onSuccess={productionLoginHandler} onError={console.log} /> | ||
) : ( | ||
<Button onClick={developmentLoginHandler}>Login</Button> | ||
); | ||
|
||
return ( | ||
<PageLayout padding={"none"} containerWidth="full"> | ||
<TopNav /> | ||
<PageLayout.Content width={"full"} padding={"normal"}> | ||
<Box>{loginButton}</Box> | ||
{isLoggingIn ? <Spinner size="large" /> : loginButton} | ||
</PageLayout.Content> | ||
</PageLayout> | ||
); | ||
|