manifold/web/hooks/use-user.ts
mantikoros 03f36cf954
User profile (#44)
* add id, userId to comment

* change user info cloud function and script; move cleanUsername to common

* change user info script

* fix rules

* add fund button: useLocation hook

* profile page

* merge

* profile stuff

* avatar uploading to storage bucket

* changeUserInfo: use transaction

* Styles for profile page

* Edit mode for profile, and more styles

Co-authored-by: James Grugett <jahooma@gmail.com>
2022-02-03 21:04:56 -06:00

35 lines
766 B
TypeScript

import { useEffect, useState } from 'react'
import { PrivateUser } from '../../common/user'
import {
listenForLogin,
listenForPrivateUser,
listenForUser,
User,
} from '../lib/firebase/users'
export const useUser = () => {
const [user, setUser] = useState<User | null | undefined>(undefined)
useEffect(() => listenForLogin(setUser), [])
const userId = user?.id
useEffect(() => {
if (userId) return listenForUser(userId, setUser)
}, [userId])
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
}