From 8e66b127b1477e53c0f6e68983ec2119f3703c06 Mon Sep 17 00:00:00 2001 From: Keiffer Acoba Date: Fri, 17 Jul 2020 17:21:58 -0400 Subject: [PATCH 1/4] Redirect to VIEW_TRIPS from SIGN_IN if user is already logged in --- frontend/src/components/SignIn/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/SignIn/index.js b/frontend/src/components/SignIn/index.js index c4f0663f..21d39d0e 100644 --- a/frontend/src/components/SignIn/index.js +++ b/frontend/src/components/SignIn/index.js @@ -1,10 +1,12 @@ import React from 'react'; +import { Redirect } from 'react-router-dom'; +import { AuthContext } from '../Auth'; import * as firebase from 'firebase/app'; import app from '../Firebase'; import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'; -import {VIEW_TRIPS} from '../../constants/routes'; +import { VIEW_TRIPS } from '../../constants/routes'; // Configure FirebaseUI. const uiConfig = { @@ -34,10 +36,21 @@ function handleAuthError(error) { } /** - * SignIn component that defines the sign-in page of the application. + * SignIn component that defines the sign-in page of the application. If the + * the user is already logged in, they will immediately be redirected to the + * VIEW_TRIPS page. Otherwise, they be given a number of providers through which + * they can sign in. */ class SignIn extends React.Component { + static contextType = AuthContext; + + /** @inheritdoc */ render() { + // Immediately go to VIEW_TRIPS page if the user is already logged in. + if (this.context !== null) { + return ; + } + return (

Please sign in:

From 098edfb0e574f31ab26f4588fa09761250d6681f Mon Sep 17 00:00:00 2001 From: Keiffer Acoba Date: Fri, 17 Jul 2020 17:44:11 -0400 Subject: [PATCH 2/4] Redirect user to LANDING when signed out --- frontend/src/components/Header/UserInfo.js | 57 +++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/Header/UserInfo.js b/frontend/src/components/Header/UserInfo.js index 3a8cc4ad..74b4c96e 100644 --- a/frontend/src/components/Header/UserInfo.js +++ b/frontend/src/components/Header/UserInfo.js @@ -1,9 +1,12 @@ -import React from 'react'; +import React from 'react'; +import { useHistory } from 'react-router-dom'; import authUtils from '../AuthUtils'; import '../../styles/header.css'; import Button from 'react-bootstrap/Button'; +import { LANDING } from '../../constants/routes.js'; + // To set spacing between each element of the component. const BOOTSTRAP_SPACING_CLASS = 'm-3 row justify-content-center align-self-center'; @@ -13,29 +16,37 @@ const BOOTSTRAP_SPACING_CLASS = * log in), the user's display name, and a Sign Out button. This component is to * be used with the Header component. */ -class UserInfo extends React.Component { - /** @inheritdoc */ - render() { - return ( -
- Your Profile -

- {authUtils.getUserDisplayName()} -

- -
- ); +const UserInfo = () => { + const history = useHistory(); + + /** + * Redirects the user to the LANDING page first before actually signing them + * out. + */ + function signOutAndRedirectToLanding() { + history.push(LANDING); + authUtils.signOut(); } + + return ( +
+ Your Profile +

+ {authUtils.getUserDisplayName()} +

+ +
+ ); } export default UserInfo; From 5b5001e808931301619c29a5253b517a6ae55633 Mon Sep 17 00:00:00 2001 From: Keiffer Acoba Date: Wed, 22 Jul 2020 15:58:32 -0400 Subject: [PATCH 3/4] Add .js --- frontend/src/components/SignIn/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/SignIn/index.js b/frontend/src/components/SignIn/index.js index 21d39d0e..c52048ca 100644 --- a/frontend/src/components/SignIn/index.js +++ b/frontend/src/components/SignIn/index.js @@ -6,7 +6,7 @@ import * as firebase from 'firebase/app'; import app from '../Firebase'; import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'; -import { VIEW_TRIPS } from '../../constants/routes'; +import { VIEW_TRIPS } from '../../constants/routes.js'; // Configure FirebaseUI. const uiConfig = { From acdec429348f059549a15d725f8b9d77053fa1c3 Mon Sep 17 00:00:00 2001 From: Keiffer Acoba Date: Mon, 27 Jul 2020 01:57:02 -0400 Subject: [PATCH 4/4] Style edits --- frontend/src/components/Header/UserInfo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Header/UserInfo.js b/frontend/src/components/Header/UserInfo.js index 74b4c96e..b10725ef 100644 --- a/frontend/src/components/Header/UserInfo.js +++ b/frontend/src/components/Header/UserInfo.js @@ -1,11 +1,11 @@ -import React from 'react'; +import React from 'react'; import { useHistory } from 'react-router-dom'; -import authUtils from '../AuthUtils'; -import '../../styles/header.css'; import Button from 'react-bootstrap/Button'; +import authUtils from '../AuthUtils'; import { LANDING } from '../../constants/routes.js'; +import '../../styles/header.css'; // To set spacing between each element of the component. const BOOTSTRAP_SPACING_CLASS =