-
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
f8df74a
commit 6198a6d
Showing
8 changed files
with
74 additions
and
14 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 +1,2 @@ | ||
VITE_API_BASE_URL="" | ||
VITE_API_BASE_URL="" | ||
VITE_OAUTH_CLIENT_ID="" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,22 +1,39 @@ | ||
import { Box, Button, PageLayout } from "@primer/react"; | ||
import { useNavigate } from "react-router"; | ||
import { GoogleLogin } from "@react-oauth/google"; | ||
import TopNav from "../TopNav/TopNav"; | ||
import { authenticationService } from "../../services/authentication"; | ||
import { isProduction } from "../../constants"; | ||
import { fetchUserProfile } from "../../services/google"; | ||
|
||
function Login() { | ||
const navigate = useNavigate(); | ||
|
||
async function handleSuccess(response) { | ||
const user = await fetchUserProfile(response); | ||
authenticationService.setUser(user); | ||
navigate("/"); | ||
} | ||
|
||
function loginHandler() { | ||
authenticationService.setUser({ name: "test" }); | ||
authenticationService.setUser({ | ||
name: "Test", | ||
given_name: "Test", | ||
email: "[email protected]", | ||
}); | ||
navigate("/"); | ||
} | ||
|
||
const loginButton = isProduction() ? ( | ||
<GoogleLogin onSuccess={handleSuccess} onError={console.log} /> | ||
) : ( | ||
<Button onClick={loginHandler}>Login</Button> | ||
); | ||
return ( | ||
<PageLayout padding={"none"} containerWidth="full"> | ||
<TopNav /> | ||
<PageLayout.Content width={"full"} padding={"normal"}> | ||
<Box> | ||
<Button onClick={loginHandler}>Login</Button> | ||
</Box> | ||
<Box>{loginButton}</Box> | ||
</PageLayout.Content> | ||
</PageLayout> | ||
); | ||
|
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
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,3 +1,11 @@ | ||
export function getApiBaseUrl() { | ||
return import.meta.env.VITE_API_BASE_URL; | ||
} | ||
|
||
export function getOAuthClientId() { | ||
return import.meta.env.VITE_OAUTH_CLIENT_ID; | ||
} | ||
|
||
export function isProduction() { | ||
return import.meta.env.PROD; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export async function fetchUserProfile(tokenResponse) { | ||
const response = await fetch( | ||
"https://www.googleapis.com/oauth2/v3/userinfo", | ||
{ headers: { Authorization: `Bearer ${tokenResponse.access_token}` } } | ||
); | ||
|
||
if (!response.ok) { | ||
console.error(response); | ||
} | ||
|
||
return await response.json(); | ||
} |