Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions frontend/src/components/Header/UserInfo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import authUtils from '../AuthUtils';
import { useHistory } from 'react-router-dom';

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 =
'm-3 row justify-content-center align-self-center';
Expand All @@ -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 (
<div className='d-flex flex-row'>
<img
className={BOOTSTRAP_SPACING_CLASS}
src={authUtils.getCurUserPhotoUrl()}
alt='Your Profile'
/>
<p className={BOOTSTRAP_SPACING_CLASS}>
{authUtils.getCurUserDisplayName()}
</p>
<Button
className={BOOTSTRAP_SPACING_CLASS}
variant='secondary'
onClick={authUtils.signOut}
>
Sign Out
</Button>
</div>
);
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();
}
Comment thread
keiffer01 marked this conversation as resolved.

return (
<div className='d-flex flex-row'>
<img
className={BOOTSTRAP_SPACING_CLASS}
src={authUtils.getCurUserPhotoUrl()}
alt='Your Profile'
/>
<p className={BOOTSTRAP_SPACING_CLASS}>
{authUtils.getCurUserDisplayName()}
</p>
<Button
className={BOOTSTRAP_SPACING_CLASS}
variant='secondary'
onClick={signOutAndRedirectToLanding}
>
Sign Out
</Button>
</div>
);
}

export default UserInfo;
16 changes: 14 additions & 2 deletions frontend/src/components/SignIn/index.js
Original file line number Diff line number Diff line change
@@ -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.js';
import { VIEW_TRIPS } from '../../constants/routes.js';

// Configure FirebaseUI.
const uiConfig = {
Expand Down Expand Up @@ -34,11 +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 <Redirect to={VIEW_TRIPS} />;
}

return (
<div>
<h1>Please sign in:</h1>
Expand Down