Skip to content

Commit

Permalink
Working on Facebook and Google login. Need to test Facebook login with
Browse files Browse the repository at this point in the history
…facebook/create-react-app#6126. Also need to add logout.
  • Loading branch information
yongish committed Dec 28, 2019
1 parent fd41030 commit a16e69f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 54 deletions.
30 changes: 19 additions & 11 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ export const confirm = (
email,
password,
confirmationCode,
history
history,
term
) => async dispatch => {
try {
await Auth.confirmSignUp(email, confirmationCode);
await Auth.signIn(email, password);
history.push("/");
if (term && term.length > 0) {
history.push("/term/" + term);
} else {
history.push("/");
}
} catch (e) {
alert(e.message);
}
Expand Down Expand Up @@ -177,7 +182,7 @@ export const signup = (
}
};

export const cognitoFB = (data, history) => async dispatch => {
export const cognitoFB = (data, history, term) => async dispatch => {
const {first_name, last_name, email, accessToken: token, expiresIn} = data;
const expires_at = expiresIn * 1000 + new Date().getTime();
dispatch({type: COGNITO_FB_REQUEST});
Expand All @@ -191,14 +196,18 @@ export const cognitoFB = (data, history) => async dispatch => {
first_name,
last_name
});
history.push("/");
if (term && term.length > 0) {
history.push("/term/" + term);
} else {
history.push("/");
}
} catch (e) {
alert(e.message);
dispatch({type: COGNITO_FB_FAILURE});
}
};

export const cognitoGoogle = (data, history) => async dispatch => {
export const cognitoGoogle = (data, history, term) => async dispatch => {
const {
profileObj: {givenName, familyName, email},
tokenId: token,
Expand All @@ -216,7 +225,11 @@ export const cognitoGoogle = (data, history) => async dispatch => {
givenName,
familyName
});
history.push("/");
if (term && term.length > 0) {
history.push("/term/" + term);
} else {
history.push("/");
}
} catch (e) {
alert(e.message);
dispatch({type: COGNITO_GOOGLE_FAILURE});
Expand Down Expand Up @@ -343,10 +356,6 @@ export const deleteSuggestion = (term, suggestionContent) => dispatch => {
);
};

export const setReferral = referral => dispatch => {
dispatch({type: SET_REFERRAL, referral});
};

export const CLEAR_SUGGESTION: string = "CLEAR_SUGGESTION";
export const COGNITO_FB_REQUEST: string = "COGNITO_FB_REQUEST";
export const COGNITO_FB_SUCCESS: string = "COGNITO_FB_SUCCESS";
Expand Down Expand Up @@ -393,7 +402,6 @@ export const SET_NEW_USER: string = "SET_NEW_USER";
export const SET_ORIGINAL_SUGGESTION: string = "SET_ORIGINAL_SUGGESTION";
export const SET_PASSWORD: string = "SET_PASSWORD";
export const SET_SUGGESTION_CONTENT: string = "SET_SUGGESTION_CONTENT";
export const SET_REFERRAL: string = "SET_REFERRAL";
export const SET_TERM: string = "SET_TERM";
export const SIGNUP_REQUEST: string = "SIGNUP_REQUEST";
export const SIGNUP_SUCCESS: string = "SIGNUP_SUCCESS";
Expand Down
9 changes: 0 additions & 9 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,14 @@ export default function App(props) {
<Related />
</div>
)}
<<<<<<< Updated upstream
{!termExists && tab === "about" && <About />}
{!termExists && tab === "home" && (
=======
{tab === "about" && <About />}
{(!term || term.length === 0) && (
>>>>>>> Stashed changes
<div className="flexGrowOne flexDisplayRow">
<Home />
<HomeRight />
</div>
)}
<<<<<<< Updated upstream
{!termExists && tab === "profile" && <Profile />}
=======
{(!term || term.length === 0) && <Profile />}
>>>>>>> Stashed changes
</div>
</div>
<BlankRight />
Expand Down
12 changes: 2 additions & 10 deletions src/components/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,8 @@ export default function Content(props) {
{suggestionVisible && !user.email && (
<div>
<p style={{marginLeft: 10}}>
To add a suggestion,{" "}
<Link
href="/login"
onClick={() => {
console.log("hi");
}}
>
log in
</Link>{" "}
or <Link href="/signup">sign up</Link>.
To add a suggestion, <Link href="/login">log in</Link> or{" "}
<Link href="/signup">sign up</Link>.
</p>
<Button
variant="contained"
Expand Down
7 changes: 5 additions & 2 deletions src/components/HeaderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {makeStyles} from "@material-ui/core/styles";
import {deepOrange, deepPurple} from "@material-ui/core/colors";
import SearchBar from "./SearchBar";

import {selectTab} from "../actions";
import {selectTab, setTerm} from "../actions";

const useStyles = makeStyles(theme => ({
button: {
Expand Down Expand Up @@ -71,12 +71,15 @@ export default function HeaderBar() {
)}
{!user.email && (
<div className="flexDisplayRowAlign">
<Link href="/login">Log in</Link>
<Link href="/login" onClick={() => dispatch(setTerm(""))}>
Log in
</Link>
<Button
variant="contained"
color="primary"
className={classes.button}
href="/signup"
onClick={() => dispatch(setTerm(""))}
>
Try free
</Button>
Expand Down
18 changes: 12 additions & 6 deletions src/components/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function SignUp() {
const email = useSelector(state => state.email);
const password = useSelector(state => state.password);
const newUser = useSelector(state => state.newUser);
const term = useSelector(state => state.term);
const dispatch = useDispatch();
const history = useHistory();

Expand Down Expand Up @@ -108,7 +109,9 @@ export default function SignUp() {
disabled={!validateConfirmationForm()}
onClick={event => {
event.preventDefault();
dispatch(confirm(email, password, confirmationCode, history));
dispatch(
confirm(email, password, confirmationCode, history, term)
);
}}
>
Verify
Expand All @@ -130,11 +133,12 @@ export default function SignUp() {
<div className={classes.paper}>
<FacebookLogin
appId="1500181530138959"
callback={response => dispatch(cognitoFB(response, history))}
onClick={() => console.log("hhhhhhhhhh")}
callback={response =>
dispatch(cognitoFB(response, history, term))
}
render={renderProps => (
<button
class="loginBtn loginBtn--facebook"
className="loginBtn loginBtn--facebook"
onClick={renderProps.onClick}
>
Continue with Facebook
Expand All @@ -148,13 +152,15 @@ export default function SignUp() {
<button
onClick={renderProps.onClick}
disabled={renderProps.disabled}
class="loginBtn loginBtn--google"
className="loginBtn loginBtn--google"
>
Continue with Google
</button>
)}
buttonText="Login"
onSuccess={response => dispatch(cognitoGoogle(response, history))}
onSuccess={response =>
dispatch(cognitoGoogle(response, history, term))
}
onFailure={response => alert(response.details)}
cookiePolicy={"single_host_origin"}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const store = configureStore(persistedState);
store.subscribe(
throttle(() => {
saveState({
user: store.getState().user
user: store.getState().user,
term: store.getState().term
});
}, 1000)
);
Expand Down
13 changes: 1 addition & 12 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
SET_ORIGINAL_SUGGESTION,
SET_PASSWORD,
SET_SUGGESTION_CONTENT,
SET_REFERRAL,
SET_TERM,
TOGGLE_EDIT,
TOGGLE_SUGGESTION_VISIBILITY
Expand Down Expand Up @@ -129,15 +128,6 @@ const newUser = (state = null, action: {type: string, newUser: string}) => {
}
};

const referral = (state = "", action: {type: string, referral: string}) => {
switch (action.type) {
case SET_REFERRAL:
return action.referral;
default:
return state;
}
};

const user = (state = {}, action: {type: string}) => {
switch (action.type) {
case LOGIN_SUCCESS:
Expand Down Expand Up @@ -335,8 +325,7 @@ const rootReducer = history =>
term,
latestTerms,
searchOptions,
user,
referral
user
});

export default rootReducer;
3 changes: 0 additions & 3 deletions src/styles/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
color: #09d3ac;
}

body { padding: 2em; }


/* Shared */
.loginBtn {
box-sizing: border-box;
Expand Down

0 comments on commit a16e69f

Please sign in to comment.