Skip to content

Commit 12f1e1a

Browse files
committed
Added Github SignIn
1 parent e57e08f commit 12f1e1a

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

src/components/GithubSignIn.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/GithubSignIn.css";
3+
import { useAuth } from "../context/AuthContext.js";
4+
5+
const GithubSignIn = () => {
6+
const { currentUser, githubSignIn } = useAuth();
7+
const [loading, setLoading] = useState(true);
8+
9+
useEffect(() => {
10+
const checkAuthentication = async () => {
11+
await new Promise((resolve) => setTimeout(resolve, 50));
12+
setLoading(false);
13+
};
14+
checkAuthentication();
15+
}, [currentUser]);
16+
17+
const handleSignIn = async () => {
18+
try {
19+
await githubSignIn();
20+
} catch (error) {
21+
console.log(error);
22+
}
23+
};
24+
25+
return loading ? null : (
26+
<button onClick={handleSignIn} className="github-sign-in-button">
27+
<img
28+
className="github-logo"
29+
src="https://www.svgrepo.com/show/452211/github.svg"
30+
loading="lazy"
31+
alt="github logo"
32+
/>
33+
<span>Login with Github</span>
34+
</button>
35+
);
36+
};
37+
38+
export default GithubSignIn;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.github-sign-in-button {
2+
display: flex;
3+
align-items: center;
4+
gap: 0.5rem;
5+
padding: 0.5rem 1rem;
6+
border: 1px solid #e2e8f0;
7+
border-radius: 0.5rem;
8+
color: #334155;
9+
background-color: black;
10+
transition: all 150ms ease-in-out;
11+
cursor: pointer;
12+
}
13+
14+
.github-sign-in-button:hover {
15+
border-color: #94a3b8;
16+
color: #0f172a;
17+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
18+
}
19+
20+
.github-logo {
21+
width: 1.5rem;
22+
height: 1.5rem;
23+
}
24+
25+
/* Dark mode styles */
26+
@media (prefers-color-scheme: dark) {
27+
.github-sign-in-button {
28+
color: #ffffff;
29+
}
30+
31+
.github-sign-in-button:hover {
32+
color: #f1f5f9;
33+
}
34+
}

src/context/AuthContext.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// 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";
2+
import { onAuthStateChanged, signOut } from "firebase/auth";
3+
import React, { useContext, useEffect, useState } from "react";
4+
import { GithubAuthProvider, GoogleAuthProvider, auth, signInWithPopup } from "../components/firebase";
55

66
const AuthContext = React.createContext();
77

@@ -17,6 +17,10 @@ export function AuthProvider({ children }) {
1717
signInWithPopup(auth, provider);
1818
}
1919

20+
const githubSignIn = ()=>{
21+
const provider = new GithubAuthProvider();
22+
signInWithPopup(auth, provider);
23+
}
2024

2125
function logOut() {
2226
signOut(auth);
@@ -31,5 +35,5 @@ export function AuthProvider({ children }) {
3135
}, [currentUser]);
3236

3337

34-
return <AuthContext.Provider value={{ currentUser, googleSignIn, logOut }}>{children}</AuthContext.Provider>;
38+
return <AuthContext.Provider value={{ currentUser, googleSignIn, githubSignIn, logOut }}>{children}</AuthContext.Provider>;
3539
}

src/pages/EditorComponent.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Box from "@mui/material/Box";
66
import { useSnackbar } from "notistack";
77
import React, { useCallback, useEffect, useRef, useState } from "react";
88
import { FaPlay } from "react-icons/fa";
9+
import GithubSignIn from "../components/GithubSignIn";
10+
import GoogleSignIn from "../components/GoogleSignIn";
911
import "../components/css/EditorComponent.css";
1012
import EditorThemeSelect from "../components/js/EditorThemeSelect";
1113
import LanguageSelect from "../components/js/LanguageSelect";
@@ -19,7 +21,6 @@ import {
1921
rapidApiHost,
2022
rapidApiKey,
2123
} from "../constants/constants";
22-
import GoogleSignIn from "../components/GoogleSignIn";
2324
import { useAuth } from "../context/AuthContext";
2425

2526
const StyledButton = styled(Button)({
@@ -56,6 +57,7 @@ const OutputLayout = styled("div")(({ theme }) => ({
5657
function EditorComponent() {
5758
const [code, setCode] = useState(null);
5859
const [output, setOutput] = useState([]);
60+
5961
const [currentLanguage, setCurrentLanguage] = useState(
6062
LANGUAGES[0].DEFAULT_LANGUAGE
6163
);
@@ -287,6 +289,8 @@ function EditorComponent() {
287289
}}>
288290
<h2>Please sign in to use the Code Editor</h2>
289291
<GoogleSignIn />
292+
<br/>
293+
<GithubSignIn/>
290294
</div>
291295
);
292296

@@ -343,7 +347,10 @@ function EditorComponent() {
343347
</div>
344348
</>
345349
) : (
350+
<>
346351
<GoogleSignIn />
352+
<GithubSignIn/>
353+
</>
347354
)}
348355
</div>
349356
<ToggleTheme />

0 commit comments

Comments
 (0)