Skip to content

Commit e57e08f

Browse files
committed
Added Google SignIn
1 parent 733c521 commit e57e08f

File tree

12 files changed

+1281
-68
lines changed

12 files changed

+1281
-68
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"react/prop-types": "off",
1414
"react/react-in-jsx-scope": "off",
1515
"indent": ["error", 2],
16-
"linebreak-style": ["error", "unix"],
16+
// "linebreak-style": ["error", "unix"],
17+
"linebreak-style": 0,
1718
"quotes": ["error", "double"],
1819
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
1920
"import/order": ["error", { "groups": [["builtin", "external", "internal"]] }],
@@ -33,6 +34,7 @@
3334
"browser": true,
3435
"node": true
3536
},
37+
3638
"settings": {
3739
"react": {
3840
"version": "detect"

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"githubPullRequests.ignoredPullRequestBranches": [
33
"main"
4+
],
5+
"cSpell.words": [
6+
"linebreak"
47
]
58
}

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@mui/material": "^6.1.1",
1111
"@mui/styled-engine-sc": "^6.0.0-alpha.18",
1212
"@snaddyvitch-dispenser/react-router-sitemap": "^1.2.6",
13+
"firebase": "^10.14.0",
1314
"monaco-themes": "^0.4.4",
1415
"notistack": "^3.0.1",
1516
"react": "^18.3.1",

src/App.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import CssBaseline from "@mui/material/CssBaseline";
55
import EditorComponent from "./pages/EditorComponent";
66
import theme from "./theme";
77
import SnackbarProvider from "./components/js/SnackbarProvider";
8+
import { AuthProvider } from "./context/AuthContext";
89
function App() {
910
return (
10-
<ThemeProvider theme={theme}>
11-
<CssBaseline />
12-
<SnackbarProvider>
13-
<BrowserRouter>
14-
<Routes>
15-
<Route path="/" element={<EditorComponent />} />
16-
<Route path="/editor" element={<EditorComponent />} />
17-
</Routes>
18-
</BrowserRouter>
19-
</SnackbarProvider>
20-
</ThemeProvider>
11+
<AuthProvider>
12+
<ThemeProvider theme={theme}>
13+
<CssBaseline />
14+
<SnackbarProvider>
15+
<BrowserRouter>
16+
<Routes>
17+
<Route path="/" element={<EditorComponent/>} />
18+
<Route path="/editor" element={<EditorComponent />} />
19+
</Routes>
20+
</BrowserRouter>
21+
</SnackbarProvider>
22+
</ThemeProvider>
23+
</AuthProvider>
2124
);
2225
}
2326

src/components/GoogleSignIn.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { useEffect, useState } from "react";
2+
import "../components/css/GoogleSignIn.css";
3+
import { useAuth } from "../context/AuthContext.js";
4+
5+
const GoogleSignIn = () => {
6+
const { currentUser, googleSignIn } = useAuth();
7+
const [loading, setLoading] = useState(true);
8+
useEffect(() => {
9+
const checkAuthentication = async () => {
10+
await new Promise((resolve) => setTimeout(resolve, 50));
11+
setLoading(false);
12+
};
13+
checkAuthentication();
14+
}, [currentUser]);
15+
16+
const handleSignIn = async () => {
17+
try {
18+
await googleSignIn();
19+
} catch (error) {
20+
console.log(error);
21+
}
22+
};
23+
24+
return loading ? null : (
25+
<button onClick={handleSignIn} className="sign-in-button">
26+
<img
27+
className="google-logo"
28+
src="https://www.svgrepo.com/show/475656/google-color.svg"
29+
loading="lazy"
30+
alt="google logo"
31+
/>
32+
<span>Login with Google</span>
33+
</button>
34+
35+
);
36+
};
37+
38+
export default GoogleSignIn;

src/components/css/EditorComponent.css

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* EditorComponent.css */
21

32
.editor-container {
43
display: flex;
@@ -32,3 +31,68 @@
3231
height: 70vh;
3332
}
3433
}
34+
35+
36+
.flex {
37+
display: flex;
38+
align-items: center;
39+
}
40+
41+
.items-center {
42+
align-items: center;
43+
}
44+
45+
.space-x-2 > *:not(:last-child) {
46+
margin-right: 8px;
47+
}
48+
49+
.welcome-text {
50+
color: #000;
51+
font-weight: bold;
52+
}
53+
54+
.signout-container {
55+
display: flex;
56+
align-items: center;
57+
border: 1px solid #D1D1D1; /* border-gray-300 */
58+
border-radius: 4px;
59+
padding: 4px 8px;
60+
background-color: #fff;
61+
transition: background-color 0.25s;
62+
}
63+
64+
.signout-container:hover {
65+
background-color: #fff;
66+
67+
transition: 0.5s all ease;
68+
}
69+
70+
.signout-button {
71+
font-weight: bold;
72+
color: #4A4A4A; /* text-gray-700 */
73+
background: none;
74+
border: none;
75+
cursor: pointer;
76+
}
77+
78+
.signout-button span:hover {
79+
color: #000; /* Black text */
80+
81+
}
82+
83+
/* Dark mode styles */
84+
@media (prefers-color-scheme: dark) {
85+
.welcome-text {
86+
color: #fff; /* text-white */
87+
}
88+
89+
.signout-container {
90+
background-color: #000; /* dark:bg-black */
91+
color: #fff ;
92+
border-color: #666; /* dark:border-gray-500 */
93+
}
94+
95+
.signout-button span {
96+
color: #fff;
97+
}
98+
}

src/components/css/GoogleSignIn.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.sign-in-button {
2+
padding: 8px 16px;
3+
border: 1px solid #E2E8F0;
4+
display: flex;
5+
align-items: center;
6+
gap: 8px;
7+
border-radius: 8px;
8+
color: #334155;
9+
background-color: #000;
10+
cursor: pointer;
11+
transition: all 0.15s ease-in-out;
12+
}
13+
14+
.sign-in-button:hover {
15+
border-color: #CBD5E1;
16+
color: #1E293B;
17+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
18+
}
19+
20+
.google-logo {
21+
width: 24px;
22+
height: 24px;
23+
}
24+
25+
.sign-in-button span {
26+
color: inherit;
27+
}
28+
29+
/* Dark mode styles */
30+
@media (prefers-color-scheme: dark) {
31+
.sign-in-button {
32+
color: #fff;
33+
}
34+
35+
.sign-in-button:hover {
36+
background-color: #fff;
37+
color: #000;
38+
}
39+
}
40+

src/components/firebase.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
import { initializeApp } from "firebase/app";
4+
import { getAuth, GoogleAuthProvider, GithubAuthProvider, signInWithPopup } from "firebase/auth";
5+
import { getFirestore } from "firebase/firestore";
6+
7+
const firebaseConfig = {
8+
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
9+
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
10+
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
11+
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
12+
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
13+
appId: process.env.REACT_APP_FIREBASE_APP_ID
14+
};
15+
16+
17+
const app = initializeApp(firebaseConfig);
18+
19+
const auth = getAuth(app);
20+
const db = getFirestore(app);
21+
22+
export { auth, GoogleAuthProvider, GithubAuthProvider, signInWithPopup, db };

src/context/AuthContext.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// src/context/AuthContext.js
2+
import React, { useContext, useState, useEffect } from "react";
3+
import { signOut, onAuthStateChanged } from "firebase/auth";
4+
import { GoogleAuthProvider, auth, signInWithPopup } from "../components/firebase";
5+
6+
const AuthContext = React.createContext();
7+
8+
export function useAuth() {
9+
return useContext(AuthContext);
10+
}
11+
12+
export function AuthProvider({ children }) {
13+
const [currentUser, setCurrentUser] = useState(null);
14+
15+
const googleSignIn = ()=>{
16+
const provider = new GoogleAuthProvider();
17+
signInWithPopup(auth, provider);
18+
}
19+
20+
21+
function logOut() {
22+
signOut(auth);
23+
}
24+
25+
useEffect(() => {
26+
const unsubscribe = onAuthStateChanged(auth, (user) => {
27+
setCurrentUser(user);
28+
});
29+
30+
return () => unsubscribe();
31+
}, [currentUser]);
32+
33+
34+
return <AuthContext.Provider value={{ currentUser, googleSignIn, logOut }}>{children}</AuthContext.Provider>;
35+
}

0 commit comments

Comments
 (0)