Fix according to reviewer feedback
This commit is contained in:
parent
53ef6e83b8
commit
18ba1a3631
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user