acc9c84e2e
* Configure functions module to allow absolute imports * Convert common imports in functions to be absolute * Convert common imports in web to be absolute * Convert lib imports in web to be absolute * Convert hooks imports in web to be absolute * Convert components imports in web to be absolute
39 lines
888 B
TypeScript
39 lines
888 B
TypeScript
import _ from 'lodash'
|
|
import { useEffect, useState } from 'react'
|
|
import { PrivateUser } from 'common/user'
|
|
import {
|
|
listenForLogin,
|
|
listenForPrivateUser,
|
|
listenForUser,
|
|
User,
|
|
} from 'web/lib/firebase/users'
|
|
import { useStateCheckEquality } from './use-state-check-equality'
|
|
|
|
export const useUser = () => {
|
|
const [user, setUser] = useStateCheckEquality<User | null | undefined>(
|
|
undefined
|
|
)
|
|
|
|
useEffect(() => listenForLogin(setUser), [setUser])
|
|
|
|
const userId = user?.id
|
|
|
|
useEffect(() => {
|
|
if (userId) return listenForUser(userId, setUser)
|
|
}, [userId, setUser])
|
|
|
|
return user
|
|
}
|
|
|
|
export const usePrivateUser = (userId?: string) => {
|
|
const [privateUser, setPrivateUser] = useState<
|
|
PrivateUser | null | undefined
|
|
>(undefined)
|
|
|
|
useEffect(() => {
|
|
if (userId) return listenForPrivateUser(userId, setPrivateUser)
|
|
}, [userId])
|
|
|
|
return privateUser
|
|
}
|