Skip to content

Commit 29febfb

Browse files
Added Google OAuth on client side and added grid in navbar
1 parent cf3e814 commit 29febfb

File tree

21 files changed

+324
-195
lines changed

21 files changed

+324
-195
lines changed

client/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1717
-->
1818
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
19+
<script src="https://apis.google.com/js/api.js"></script>
1920
<!--
2021
Notice the use of %PUBLIC_URL% in the tags above.
2122
It will be replaced with the URL of the `public` folder during the build.

client/src/actions/index.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SAVE_QUERY_STATUS,
99
SHIPPING_ADDRESS_CONFIRMED,
1010
PAYMENT_INFO_CONFIRMED,
11-
PAYMENT_RESPONSE, CART_TOTAL, HANDLE_SIGN_UP_RESET,
11+
PAYMENT_RESPONSE, CART_TOTAL, HANDLE_SIGN_UP_RESET, HANDLE_GOOGLE_AUTH_SIGN_IN, HANDLE_GOOGLE_AUTH_SIGN_OUT,
1212
} from './types';
1313
import {INTERNAL_SERVER_ERROR_CODE, BAD_REQUEST_ERROR_CODE} from '../constants/http_error_codes'
1414
import {SHOPPERS_PRODUCT_INFO_COOKIE, CART_TOTAL_COOKIE, AUTH_DETAILS_COOKIE} from '../constants/cookies'
@@ -43,7 +43,7 @@ export const setPaymentInfo = payload => {
4343
}
4444
}
4545

46-
export const signIn = formValues => async (dispatch) => {
46+
export const signIn = formValues => async dispatch => {
4747
log.info(`[ACTION]: signIn API is invoked formValues = ${formValues}`)
4848

4949
const hash = Base64.encode(`${formValues.username}:${formValues.password}`);
@@ -75,6 +75,54 @@ export const signOut = () => {
7575
}
7676
}
7777

78+
export const signInUsingOAuth = googleAuth => async dispatch => {
79+
log.info(`[signInUsingOAuth] googleAuth = ${googleAuth}`)
80+
81+
// check if not signed in
82+
if (googleAuth && !googleAuth.isSignedIn.get()) {
83+
log.info('[signInUsingOAuth] User has not signed in yet')
84+
85+
// sign in
86+
googleAuth.signIn(JSON.parse(googleAuth.currentUser.get().getId())).then(() => {
87+
// if sign in works
88+
if (googleAuth.isSignedIn.get()) {
89+
log.info('[signInUsingOAuth] User is signed in successfully')
90+
// here we are sure that we signed in and now dispatch.
91+
dispatch({
92+
type: HANDLE_GOOGLE_AUTH_SIGN_IN,
93+
payload: {
94+
firstName: "Norman",
95+
oAuth: googleAuth
96+
}
97+
})
98+
99+
history.push("/");
100+
}
101+
})
102+
}
103+
}
104+
105+
export const signOutUsingOAuth = googleAuth => async dispatch => {
106+
log.info(`[signOutUsingOAuth] googleAuth = ${googleAuth}, ` +
107+
`googleAuth.isSignedIn.get() = ${googleAuth.isSignedIn.get()}`)
108+
109+
// if signed in then only try to sign out
110+
if (googleAuth && googleAuth.isSignedIn.get()) {
111+
112+
log.info(`[signOutUsingOAuth] trying to signout`)
113+
googleAuth.signOut().then(() => {
114+
if (!googleAuth.isSignedIn.get()) {
115+
log.info(`[signOutUsingOAuth] Successfully signed out`)
116+
dispatch({
117+
type: HANDLE_GOOGLE_AUTH_SIGN_OUT,
118+
payload: null
119+
})
120+
}
121+
});
122+
}
123+
}
124+
125+
78126
export const resetSignUp = () => {
79127
return {
80128
type: HANDLE_SIGN_UP_RESET

client/src/actions/types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
export const HANDLE_SIGN_IN= "HANDLE_SIGN_IN";
44
export const HANDLE_SIGN_OUT= "HANDLE_SIGN_OUT";
55
export const HANDLE_SIGN_IN_ERROR= "HANDLE_SIGN_IN_ERROR";
6+
export const SET_GOOGLE_AUTH= "SET_GOOGLE_AUTH";
7+
export const HANDLE_GOOGLE_AUTH_SIGN_IN= "HANDLE_GOOGLE_AUTH_SIGN_IN";
8+
export const HANDLE_GOOGLE_AUTH_SIGN_OUT= "HANDLE_GOOGLE_AUTH_SIGN_OUT";
69
export const HANDLE_SIGN_UP_ERROR= "HANDLE_SIGN_UP_ERROR";
710
export const HANDLE_SIGN_UP_RESET= "HANDLE_SIGN_UP_RESET";
811
export const HANDLE_TAB_HOVER_EVENT = "HANDLE_TAB_HOVER_EVENT";

client/src/components/routes/cancelPayment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import log from 'loglevel'
33
import {Grid} from "@material-ui/core";
44
import {Link} from "react-router-dom";
55
import {CHECKOUT_ROUTE} from "../../constants/react_routes";
6+
import {DocumentTitle} from "../ui/documentTitle";
67

78
export const CancelPayment = () => {
89

910
log.info('[CancelPayment] Rendering SuccessPayment Component')
1011
return (
1112
<Grid item xs={8} container style={{padding: "2rem", margin: "2rem", border: "1px solid black",
1213
fontSize: "1.2rem"}}>
14+
15+
<DocumentTitle title="Payment Failed"/>
16+
1317
<Grid item xs={12}
1418
style={{border: "1px solid red", padding: "2rem", fontSize: "2rem", fontWeight: "bold"}}>
1519
Payment Cancelled. Sorry your payment is declined.

client/src/components/routes/checkout/checkout.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import PaymentButton from "./paymentButton";
1414
import {useAddProductsToShoppingBag} from "../../../hooks/useAddProductsToShoppingBag";
1515
import {getDataViaAPI} from "../../../actions";
1616
import {useCartTotal} from "../../../hooks/useCartTotal";
17+
import {DocumentTitle} from "../../ui/documentTitle";
1718
// import {Elements, ElementsConsumer} from "@stripe/react-stripe-js";
1819
// import Payment from "./payment"
1920

@@ -103,6 +104,8 @@ function Checkout(props) {
103104

104105
<Grid item xs={12} sm={11} md={5}>
105106

107+
<DocumentTitle title="Checkout"/>
108+
106109
<Accordion square expanded>
107110
<AccordionSummary aria-controls={`${shippingAddressPanel}-content`}
108111
id={`${shippingAddressPanel}-header`}>

client/src/components/routes/detail/productDetails.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import _ from "lodash";
2020
import {PRODUCT_BY_ID_DATA_API} from "../../../constants/api_routes";
2121
import {SHOPPERS_PRODUCT_INFO_COOKIE} from "../../../constants/cookies";
2222
import {HOME_ROUTE} from "../../../constants/react_routes";
23+
import {DocumentTitle} from "../../ui/documentTitle";
2324

2425
export const useButtonStyles = makeStyles(() => ({
2526
buttonStartIcon: {
@@ -166,6 +167,7 @@ function ProductDetails(props) {
166167
log.info(`[Product Detail] Rendering Detail Component. selectedProduct = ${JSON.stringify(selectedProduct)}`)
167168
return (
168169
<>
170+
<DocumentTitle title="Product Details"/>
169171
<Box display="flex" p={3}>
170172
<BreadcrumbsSection linkList={breadcrumbLinks}/>
171173
</Box>

0 commit comments

Comments
 (0)