-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ad37d92
commit 4fc81d9
Showing
20 changed files
with
2,446 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ yarn-error.log* | |
|
||
# vercel | ||
.vercel | ||
|
||
config.js |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
import { initializeApp } from "firebase/app"; | ||
import { getFirestore, getDocs, getDoc, doc } from 'firebase/firestore' | ||
import { getAuth, signInWithPopup, signOut, GithubAuthProvider } from 'firebase/auth'; | ||
|
||
const FirebaseConfig = { | ||
apiKey: process.env.NEXT_PUBLIC_API_KEY, | ||
authDomain: process.env.NEXT_PUBLIC_AUTH_DOMAIN, | ||
projectId: process.env.NEXT_PUBLIC_PROJECT_ID, | ||
storageBucket: process.env.NEXT_PUBLIC_STORAGE_BUCKET, | ||
messagingSenderId: process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID, | ||
appId: process.env.NEXT_PUBLIC_APP_ID | ||
}; | ||
|
||
// Initialize Firebase | ||
const app = initializeApp(FirebaseConfig); | ||
const auth = getAuth(); | ||
const database = getFirestore(); | ||
|
||
export { auth, signInWithPopup, GithubAuthProvider, signOut, database, getDocs, getDoc, doc }; |
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 |
---|---|---|
|
@@ -105,5 +105,6 @@ | |
> div { | ||
background: var(--green); | ||
height: inherit; | ||
transition: width 1s linear; | ||
} | ||
} |
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
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,72 @@ | ||
import { createContext, ReactNode, useEffect, useState } from 'react'; | ||
import { auth, signInWithPopup, GithubAuthProvider } from '../../service'; | ||
|
||
type ReactChildren = { | ||
children: ReactNode; | ||
} | ||
|
||
type UserProps = { | ||
id: string; | ||
name: string; | ||
avatar: string; | ||
|
||
} | ||
|
||
type AuthContextProps = { | ||
user: UserProps; | ||
signInWithGithub: ()=>void; | ||
} | ||
|
||
const AuthContext = createContext({}as AuthContextProps); | ||
|
||
function AuthContextProvider({children}:ReactChildren){ | ||
const [user, setUser] = useState<UserProps>() | ||
|
||
async function signInWithGithub(){ | ||
try { | ||
//const auth = getAuth(); | ||
const provider = new GithubAuthProvider(); | ||
const { user } = await signInWithPopup(auth,provider); | ||
console.log({user}); | ||
const _user = { | ||
id: user.uid, | ||
name: user.displayName, | ||
avatar: user.photoURL | ||
} | ||
setUser(_user); | ||
console.log(_user); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
const subscribe = auth.onAuthStateChanged(user=>{ | ||
if(user){ | ||
const { displayName, photoURL, uid } = user; | ||
const _user = { | ||
id: uid, | ||
name: displayName, | ||
avatar: photoURL | ||
} | ||
setUser(_user); | ||
} | ||
}) | ||
|
||
return () => { | ||
subscribe(); | ||
} | ||
}, []) | ||
|
||
return( | ||
<AuthContext.Provider value={{ | ||
user, | ||
signInWithGithub | ||
}}> | ||
{children} | ||
</AuthContext.Provider> | ||
) | ||
} | ||
|
||
export { AuthContext, AuthContextProvider } |
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,6 @@ | ||
import { useContext } from "react"; | ||
import { AuthContext } from "../context/AuthContext"; | ||
|
||
export function useAuth(){ | ||
return useContext(AuthContext); | ||
} |
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
Oops, something went wrong.