456d9398a1
* Load bets and comments tabs data on user page independently * Implement basic pagination on profile comments list * Tweak server auth to return `null` instead of `undefined` * Switch to SSR for user page * Fix lint * Fix broken contract fetching in user bets list * Tidying
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { useRouter } from 'next/router'
|
|
import React from 'react'
|
|
|
|
import {
|
|
getUserByUsername,
|
|
getUserAndPrivateUser,
|
|
User,
|
|
UserAndPrivateUser,
|
|
} from 'web/lib/firebase/users'
|
|
import { UserPage } from 'web/components/user-page'
|
|
import Custom404 from '../404'
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
|
import { GetServerSideProps } from 'next'
|
|
import { authenticateOnServer } from 'web/lib/firebase/server-auth'
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|
const creds = await authenticateOnServer(ctx)
|
|
const username = ctx.params!.username as string // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
|
const [auth, user] = (await Promise.all([
|
|
creds != null ? getUserAndPrivateUser(creds.user.uid) : null,
|
|
getUserByUsername(username),
|
|
])) as [UserAndPrivateUser | null, User | null]
|
|
return { props: { auth, user } }
|
|
}
|
|
|
|
export default function UserProfile(props: { user: User | null }) {
|
|
const { user } = props
|
|
|
|
const router = useRouter()
|
|
const { username } = router.query as {
|
|
username: string
|
|
}
|
|
|
|
useTracking('view user profile', { username })
|
|
|
|
return user ? <UserPage user={user} /> : <Custom404 />
|
|
}
|