Skip to content

Commit 0b0fe7d

Browse files
committed
resolved_merge_conflicts
1 parent 5f40cd4 commit 0b0fe7d

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
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: 9 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);
@@ -32,5 +36,6 @@ export function AuthProvider({ children }) {
3236
}, [currentUser]);
3337

3438

35-
return <AuthContext.Provider value={{ currentUser, setCurrentUser, googleSignIn, logOut }}>{children}</AuthContext.Provider>;
39+
40+
return <AuthContext.Provider value={{ currentUser, googleSignIn, githubSignIn, logOut }}>{children}</AuthContext.Provider>;
3641
}

src/pages/Landingpage.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useContext } from "react";
55
import { SocketContext } from "../context/socket";
66
import Header from "../components/Header"
77
import GoogleSignIn from "../components/GoogleSignIn";
8+
import GithubSignIn from "../components/GithubSignIn";
89
import { useAuth } from "../context/AuthContext";
910

1011
const CreatePopUp = ({ setTogglePopUp, setRooms, rooms }) => {
@@ -81,6 +82,8 @@ function Landingpage() {
8182
>
8283
<h2>Please sign in to use the Code Editor</h2>
8384
<GoogleSignIn />
85+
<br/>
86+
<GithubSignIn/>
8487
</div>
8588
);
8689

0 commit comments

Comments
 (0)