-
Notifications
You must be signed in to change notification settings - Fork 5
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
29 changed files
with
2,729 additions
and
426 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 |
---|---|---|
@@ -1 +1,6 @@ | ||
NEXT_PUBLIC_GOOGLE_MAP_KEY=AIzaSyAnHNX_kANW6oxjdcDoOs8VVwDAOsbA9ZY | ||
<<<<<<< HEAD | ||
GITHUB_ID= 06278944971ada50241b | ||
GITHUB_SECRET = 0a489dbefa1825e83f17ea3d5bdeeee9bc78f7c3 | ||
======= | ||
NEXT_PUBLIC_GOOGLE_MAP_KEY=AIzaSyAnHNX_kANW6oxjdcDoOs8VVwDAOsbA9ZY | ||
>>>>>>> 219fb38c827154d2218e531b50b21e0d94eef5af |
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,55 @@ | ||
import { auth } from "firebase.config"; | ||
import { | ||
createUserWithEmailAndPassword, | ||
onAuthStateChanged, | ||
signInWithEmailAndPassword, | ||
signOut, | ||
} from "firebase/auth"; | ||
import { createContext, useContext, useEffect, useState } from "react"; | ||
// import { auth } from '../config/firebase' | ||
|
||
const AuthContext = createContext({}); | ||
|
||
export const useAuth = () => useContext(AuthContext); | ||
|
||
export const AuthContextProvider = ({ children }) => { | ||
const [user, setUser] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
// console.log(user); | ||
|
||
useEffect(() => { | ||
const unsubscribe = onAuthStateChanged(auth, (user) => { | ||
if (user) { | ||
setUser({ | ||
uid: user.uid, | ||
email: user.email, | ||
displayName: user.displayName, | ||
}); | ||
} else { | ||
setUser(null); | ||
} | ||
setLoading(false); | ||
}); | ||
|
||
return () => unsubscribe(); | ||
}, []); | ||
|
||
const signup = (email, password) => { | ||
return createUserWithEmailAndPassword(auth, email, password); | ||
}; | ||
|
||
const login = (email, password) => { | ||
return signInWithEmailAndPassword(auth, email, password); | ||
}; | ||
|
||
const logout = async () => { | ||
setUser(null); | ||
await signOut(auth); | ||
}; | ||
|
||
return ( | ||
<AuthContext.Provider value={{ user, login, signup, logout }}> | ||
{loading ? null : children} | ||
</AuthContext.Provider> | ||
); | ||
}; |
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,27 @@ | ||
import { createContext, useEffect, useState } from "react"; | ||
|
||
const AuthContext = createContext({}); | ||
// localStorage.setItem(JSON.stringify()) | ||
|
||
export const AuthProvider = ({ children }) => { | ||
const [auth, setAuth] = useState(null); | ||
useEffect(() => { | ||
if (auth === null) return; | ||
localStorage.setItem("user", JSON.stringify(auth)); | ||
}, [auth]); | ||
useEffect(() => { | ||
const data = | ||
localStorage.getItem("user") === "undefined" | ||
? {} | ||
: JSON.parse(localStorage.getItem("user")); | ||
setAuth(data); | ||
}, []); | ||
|
||
return ( | ||
<AuthContext.Provider value={{ auth, setAuth }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
import { initializeApp } from "firebase/app"; | ||
import { getAuth } from "firebase/auth"; | ||
|
||
const firebaseConfig = { | ||
apiKey: "AIzaSyC0zI86ZYBP-xrPj5jiydZw4bKuEPx-vXU", | ||
authDomain: "student-store-7cf9c.firebaseapp.com", | ||
projectId: "student-store-7cf9c", | ||
storageBucket: "student-store-7cf9c.appspot.com", | ||
messagingSenderId: "604088151357", | ||
appId: "1:604088151357:web:54360215fa3b0cc4fb6954", | ||
measurementId: "G-6RJH6GQHKG", | ||
}; | ||
|
||
const app = initializeApp(firebaseConfig); | ||
export const auth = getAuth(); |
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,9 @@ | ||
import { useContext } from "react"; | ||
|
||
import AuthContext from "../contexts/AuthProvider"; | ||
|
||
const useAuth = () => { | ||
return useContext(AuthContext); | ||
}; | ||
|
||
export default useAuth; |
Oops, something went wrong.