Skip to content

Commit ff85e32

Browse files
authored
Merge pull request #139 from Anikesh02/SignInWithGoogle
Added Github SignIn
2 parents 5f648a2 + 12f1e1a commit ff85e32

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)({
@@ -61,6 +62,7 @@ const WelcomeText = styled("span")(({ theme }) => ({
6162
function EditorComponent() {
6263
const [code, setCode] = useState(null);
6364
const [output, setOutput] = useState([]);
65+
6466
const [currentLanguage, setCurrentLanguage] = useState(
6567
LANGUAGES[0].DEFAULT_LANGUAGE
6668
);
@@ -294,6 +296,8 @@ function EditorComponent() {
294296
>
295297
<h2>Please sign in to use the Code Editor</h2>
296298
<GoogleSignIn />
299+
<br/>
300+
<GithubSignIn/>
297301
</div>
298302
);
299303

@@ -355,7 +359,10 @@ function EditorComponent() {
355359
</div>
356360
</>
357361
) : (
362+
<>
358363
<GoogleSignIn />
364+
<GithubSignIn/>
365+
</>
359366
)}
360367
</div>
361368
<ToggleTheme />

0 commit comments

Comments
 (0)