Allow logging in with Firebase (#2)
* Pin package.json to exact version * Fix according to reviewer feedback
This commit is contained in:
parent
992c245837
commit
7ec3da5504
|
@ -7,7 +7,7 @@ const firebaseConfig = {
|
||||||
storageBucket: 'mantic-markets.appspot.com',
|
storageBucket: 'mantic-markets.appspot.com',
|
||||||
messagingSenderId: '128925704902',
|
messagingSenderId: '128925704902',
|
||||||
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
||||||
measurementId: '${config.measurementId}',
|
measurementId: 'G-SSFK1Q138D',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Firebase
|
// Initialize Firebase
|
||||||
|
|
|
@ -32,14 +32,14 @@ export async function setUser(userId: string, user: User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CACHED_USER_KEY = 'CACHED_USER_KEY'
|
const CACHED_USER_KEY = 'CACHED_USER_KEY'
|
||||||
export function listenForLogin(onUser: (user: User) => void) {
|
export function listenForLogin(onUser: (_user: User) => void) {
|
||||||
// Immediately load any persisted user object from browser cache.
|
// Immediately load any persisted user object from browser cache.
|
||||||
const cachedUser = localStorage.getItem(CACHED_USER_KEY)
|
const cachedUser = localStorage.getItem(CACHED_USER_KEY)
|
||||||
if (cachedUser) {
|
if (cachedUser) {
|
||||||
onUser(JSON.parse(cachedUser))
|
onUser(JSON.parse(cachedUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
onAuthStateChanged(auth, async (user) => {
|
return onAuthStateChanged(auth, async (user) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
let fetchedUser = await getUser(user.uid)
|
let fetchedUser = await getUser(user.uid)
|
||||||
if (!fetchedUser) {
|
if (!fetchedUser) {
|
||||||
|
@ -65,6 +65,7 @@ export function listenForLogin(onUser: (user: User) => void) {
|
||||||
} else {
|
} else {
|
||||||
// User logged out; reset to the empty object
|
// User logged out; reset to the empty object
|
||||||
onUser({} as User)
|
onUser({} as User)
|
||||||
|
localStorage.removeItem(CACHED_USER_KEY)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,6 @@ export async function firebaseLogin() {
|
||||||
|
|
||||||
export async function firebaseLogout() {
|
export async function firebaseLogout() {
|
||||||
auth.signOut()
|
auth.signOut()
|
||||||
localStorage.removeItem(CACHED_USER_KEY)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const storage = getStorage(app)
|
const storage = getStorage(app)
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "1.4.2",
|
"@headlessui/react": "1.4.2",
|
||||||
"@heroicons/react": "1.0.5",
|
"@heroicons/react": "1.0.5",
|
||||||
"chart.js": "^3.6.1",
|
"chart.js": "3.6.1",
|
||||||
"daisyui": "^1.16.2",
|
"daisyui": "1.16.2",
|
||||||
"firebase": "^9.6.0",
|
"firebase": "9.6.0",
|
||||||
"next": "12.0.4",
|
"next": "12.0.4",
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-chartjs-2": "^4.0.0",
|
"react-chartjs-2": "4.0.0",
|
||||||
"react-dom": "17.0.2"
|
"react-dom": "17.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user