Skip to content

Commit

Permalink
Merge pull request #20 from uwblueprint/S24/daniel/changing-login-and…
Browse files Browse the repository at this point in the history
…-landing-page

S24/daniel/changing login and landing page
  • Loading branch information
MinIcecream authored Jul 3, 2024
2 parents f69d19c + 1bb65e7 commit f2231b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 54 deletions.
8 changes: 6 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Login from "./components/auth/Login";
import Signup from "./components/auth/Signup";
import PrivateRoute from "./components/auth/PrivateRoute";
import CreatePage from "./components/pages/CreatePage";
import Default from "./components/pages/Default";
import PetListPage from "./components/pages/PetListPage";
import DisplayPage from "./components/pages/DisplayPage";
import SimpleEntityCreatePage from "./components/pages/SimpleEntityCreatePage";
import SimpleEntityDisplayPage from "./components/pages/SimpleEntityDisplayPage";
Expand Down Expand Up @@ -55,7 +55,11 @@ const App = (): React.ReactElement => {
<Switch>
<Route exact path={Routes.LOGIN_PAGE} component={Login} />
<Route exact path={Routes.SIGNUP_PAGE} component={Signup} />
<PrivateRoute exact path={Routes.HOME_PAGE} component={Default} />
<PrivateRoute
exact
path={Routes.HOME_PAGE}
component={PetListPage}
/>
<PrivateRoute
exact
path={Routes.CREATE_ENTITY_PAGE}
Expand Down
54 changes: 2 additions & 52 deletions frontend/src/components/auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,20 @@
import React, { useContext, useState } from "react";
import { Redirect, useHistory } from "react-router-dom";
import {
GoogleLogin,
GoogleLoginResponse,
GoogleLoginResponseOffline,
} from "react-google-login";
import { Redirect } from "react-router-dom";

import authAPIClient from "../../APIClients/AuthAPIClient";
import { HOME_PAGE, SIGNUP_PAGE } from "../../constants/Routes";
import { HOME_PAGE } from "../../constants/Routes";
import AuthContext from "../../contexts/AuthContext";
import { AuthenticatedUser } from "../../types/AuthTypes";

type GoogleResponse = GoogleLoginResponse | GoogleLoginResponseOffline;

type GoogleErrorResponse = {
error: string;
details: string;
};

const Login = (): React.ReactElement => {
const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext);
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const history = useHistory();

const onLogInClick = async () => {
const user: AuthenticatedUser = await authAPIClient.login(email, password);
setAuthenticatedUser(user);
};

const onSignUpClick = () => {
history.push(SIGNUP_PAGE);
};

const onGoogleLoginSuccess = async (tokenId: string) => {
const user: AuthenticatedUser = await authAPIClient.loginWithGoogle(
tokenId,
);
setAuthenticatedUser(user);
};

if (authenticatedUser) {
return <Redirect to={HOME_PAGE} />;
}
Expand Down Expand Up @@ -73,32 +48,7 @@ const Login = (): React.ReactElement => {
Log In
</button>
</div>
<GoogleLogin
clientId={process.env.REACT_APP_OAUTH_CLIENT_ID || ""}
buttonText="Login with Google"
onSuccess={(response: GoogleResponse): void => {
if ("tokenId" in response) {
onGoogleLoginSuccess(response.tokenId);
} else {
// eslint-disable-next-line no-alert
window.alert(response);
}
}}
onFailure={(error: GoogleErrorResponse) =>
// eslint-disable-next-line no-alert
window.alert(JSON.stringify(error))
}
/>
</form>
<div>
<button
className="btn btn-primary"
type="button"
onClick={onSignUpClick}
>
Sign Up
</button>
</div>
</div>
);
};
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/components/pages/PetListPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

const GetPage = (): React.ReactElement => {
return (
<div style={{ textAlign: "center", width: "25%", margin: "0px auto" }}>
<h1>Pets</h1>
</div>
);
};

export default GetPage;

0 comments on commit f2231b1

Please sign in to comment.