Skip to content

Commit 0943eb2

Browse files
authored
Google Sign in - Login (#11)
* fixes varios * node fix, pagination and margins * Google Sign in - Login added, minor changes * Google auth added
1 parent 652f9c8 commit 0943eb2

File tree

12 files changed

+117
-9
lines changed

12 files changed

+117
-9
lines changed

src/.env renamed to .env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ REACT_APP_API_KEY = fe7f525d019d7186e76683b4233c4a0c
33
//b1e66cf7b4d8b4bb07238f7a3e8bfe15
44
//bba2ad02b4ec7888859b671bb039179f
55
//b290e192611b0edd8fef1d95bb9a17ae;
6+
REACT_APP_GOOGLE_CLIENT_ID=423678433872-li4489tkutnb0kk944olk1je7ramfdh9.apps.googleusercontent.com

Login.js

Whitespace-only changes.

Logout.js

Whitespace-only changes.

package-lock.json

Lines changed: 26 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
"@material-ui/icons": "^4.11.3",
1414
"@material-ui/lab": "^4.0.0-alpha.61",
1515
"@mui/material": "^5.8.2",
16+
"@react-oauth/google": "^0.12.2",
1617
"@testing-library/jest-dom": "^5.16.4",
1718
"@testing-library/react": "^13.2.0",
1819
"@testing-library/user-event": "^13.5.0",
1920
"axios": "^0.27.2",
21+
"jwt-decode": "^4.0.0",
2022
"nvm": "^0.0.4",
2123
"react": "^18.1.0",
2224
"react-alice-carousel": "^2.6.1",

src/App.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Container from "@material-ui/core/Container";
2-
import React from "react";
2+
import React, { useState } from "react";
33
import { Route, BrowserRouter as Router, Switch } from "react-router-dom";
44
import ConsentDialog from "./components/ConsentDialog/ConsentDialog";
55
import Header from "./components/Header/Header";
@@ -9,13 +9,27 @@ import Search from "./components/Pages/Search/Search";
99
import Series from "./components/Pages/Series/Series";
1010
import Trending from "./components/Pages/Trending/Trending";
1111
import useGTM from "./hooks/useGTM";
12+
import Login from './components/Login';
13+
import Logout from './components/Logout';
1214

1315
function App() {
1416
const { consentGiven, handleConsent } = useGTM();
17+
const [user, setUser] = useState(null);
1518

1619
return (
1720
<Router>
1821
<Header />
22+
<div style={{ position: 'fixed', top: 15, right: 15, zIndex: 101, color: 'white' }}>
23+
{user ? (
24+
<div style={{ display: 'flex', alignItems: 'center' }}>
25+
<img src={user.picture} alt={user.name} style={{ borderRadius: '50%', width: '40px', marginRight: '10px' }} />
26+
<span>Welcome, {user.name}</span>
27+
<Logout setUser={setUser} />
28+
</div>
29+
) : (
30+
<Login setUser={setUser} />
31+
)}
32+
</div>
1933
<div className="app">
2034
<Container>
2135
<Switch>

src/components/Login.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { GoogleLogin } from '@react-oauth/google';
3+
import { jwtDecode } from 'jwt-decode';
4+
5+
const Login = ({ setUser }) => {
6+
const onSuccess = (res) => {
7+
const userObject = jwtDecode(res.credential);
8+
console.log('Login Success:', userObject);
9+
setUser(userObject);
10+
// Here, you would typically send the token (res.credential) to your backend
11+
// to verify the user and create a session.
12+
};
13+
14+
const onError = () => {
15+
console.log('Login Failed');
16+
};
17+
18+
return (
19+
<div>
20+
<GoogleLogin
21+
onSuccess={onSuccess}
22+
onError={onError}
23+
useOneTap
24+
/>
25+
</div>
26+
);
27+
};
28+
29+
export default Login;
30+

src/components/Logout.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { googleLogout } from '@react-oauth/google';
3+
4+
const Logout = ({ setUser }) => {
5+
const handleLogout = () => {
6+
googleLogout();
7+
setUser(null);
8+
console.log('Logout Successful');
9+
};
10+
11+
return (
12+
<button onClick={handleLogout} style={{ marginLeft: '10px' }}>
13+
Logout
14+
</button>
15+
);
16+
};
17+
18+
export default Logout;
19+

src/components/Pages/Search/Search.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
display: flex;
33
margin: 15px 0;
44
padding-top: 100px;
5-
}
5+
}

src/components/Pages/Search/Search.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ const Search = () => {
2727
main: "#fff",
2828
},
2929
},
30+
overrides: {
31+
MuiFilledInput: {
32+
input: {
33+
color: "#5548ceff", // A light blue for better contrast
34+
},
35+
},
36+
},
3037
});
3138

3239
const fetchSearch = async () => {

0 commit comments

Comments
 (0)