-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,281 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"githubPullRequests.ignoredPullRequestBranches": [ | ||
"main" | ||
], | ||
"cSpell.words": [ | ||
"linebreak" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import "../components/css/GoogleSignIn.css"; | ||
import { useAuth } from "../context/AuthContext.js"; | ||
|
||
const GoogleSignIn = () => { | ||
const { currentUser, googleSignIn } = useAuth(); | ||
const [loading, setLoading] = useState(true); | ||
useEffect(() => { | ||
const checkAuthentication = async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 50)); | ||
setLoading(false); | ||
}; | ||
checkAuthentication(); | ||
}, [currentUser]); | ||
|
||
const handleSignIn = async () => { | ||
try { | ||
await googleSignIn(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
return loading ? null : ( | ||
<button onClick={handleSignIn} className="sign-in-button"> | ||
<img | ||
className="google-logo" | ||
src="https://www.svgrepo.com/show/475656/google-color.svg" | ||
loading="lazy" | ||
alt="google logo" | ||
/> | ||
<span>Login with Google</span> | ||
</button> | ||
|
||
); | ||
}; | ||
|
||
export default GoogleSignIn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.sign-in-button { | ||
padding: 8px 16px; | ||
border: 1px solid #E2E8F0; | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
border-radius: 8px; | ||
color: #334155; | ||
background-color: #000; | ||
cursor: pointer; | ||
transition: all 0.15s ease-in-out; | ||
} | ||
|
||
.sign-in-button:hover { | ||
border-color: #CBD5E1; | ||
color: #1E293B; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.google-logo { | ||
width: 24px; | ||
height: 24px; | ||
} | ||
|
||
.sign-in-button span { | ||
color: inherit; | ||
} | ||
|
||
/* Dark mode styles */ | ||
@media (prefers-color-scheme: dark) { | ||
.sign-in-button { | ||
color: #fff; | ||
} | ||
|
||
.sign-in-button:hover { | ||
background-color: #fff; | ||
color: #000; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
import { initializeApp } from "firebase/app"; | ||
import { getAuth, GoogleAuthProvider, GithubAuthProvider, signInWithPopup } from "firebase/auth"; | ||
import { getFirestore } from "firebase/firestore"; | ||
|
||
const firebaseConfig = { | ||
apiKey: process.env.REACT_APP_FIREBASE_API_KEY, | ||
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN, | ||
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID, | ||
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET, | ||
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID, | ||
appId: process.env.REACT_APP_FIREBASE_APP_ID | ||
}; | ||
|
||
|
||
const app = initializeApp(firebaseConfig); | ||
|
||
const auth = getAuth(app); | ||
const db = getFirestore(app); | ||
|
||
export { auth, GoogleAuthProvider, GithubAuthProvider, signInWithPopup, db }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// src/context/AuthContext.js | ||
import React, { useContext, useState, useEffect } from "react"; | ||
import { signOut, onAuthStateChanged } from "firebase/auth"; | ||
import { GoogleAuthProvider, auth, signInWithPopup } from "../components/firebase"; | ||
|
||
const AuthContext = React.createContext(); | ||
|
||
export function useAuth() { | ||
return useContext(AuthContext); | ||
} | ||
|
||
export function AuthProvider({ children }) { | ||
const [currentUser, setCurrentUser] = useState(null); | ||
|
||
const googleSignIn = ()=>{ | ||
const provider = new GoogleAuthProvider(); | ||
signInWithPopup(auth, provider); | ||
} | ||
|
||
|
||
function logOut() { | ||
signOut(auth); | ||
} | ||
|
||
useEffect(() => { | ||
const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
setCurrentUser(user); | ||
}); | ||
|
||
return () => unsubscribe(); | ||
}, [currentUser]); | ||
|
||
|
||
return <AuthContext.Provider value={{ currentUser, googleSignIn, logOut }}>{children}</AuthContext.Provider>; | ||
} |
Oops, something went wrong.