2021-12-16 00:52:19 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2022-07-11 00:42:34 +00:00
|
|
|
import React from 'react'
|
2021-12-16 21:17:32 +00:00
|
|
|
|
2022-08-13 03:42:58 +00:00
|
|
|
import {
|
|
|
|
getUserByUsername,
|
|
|
|
getUserAndPrivateUser,
|
|
|
|
User,
|
|
|
|
UserAndPrivateUser,
|
|
|
|
} from 'web/lib/firebase/users'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { UserPage } from 'web/components/user-page'
|
2022-01-16 03:09:15 +00:00
|
|
|
import Custom404 from '../404'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2022-08-13 03:42:58 +00:00
|
|
|
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([
|
2022-09-01 05:13:26 +00:00
|
|
|
creds != null ? getUserAndPrivateUser(creds.uid) : null,
|
2022-08-13 03:42:58 +00:00
|
|
|
getUserByUsername(username),
|
|
|
|
])) as [UserAndPrivateUser | null, User | null]
|
|
|
|
return { props: { auth, user } }
|
2022-07-11 00:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function UserProfile(props: { user: User | null }) {
|
|
|
|
const { user } = props
|
2021-12-16 00:52:19 +00:00
|
|
|
|
|
|
|
const router = useRouter()
|
2022-07-25 20:27:09 +00:00
|
|
|
const { username } = router.query as {
|
2022-06-22 16:35:50 +00:00
|
|
|
username: string
|
|
|
|
}
|
2021-12-16 21:17:32 +00:00
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view user profile', { username })
|
|
|
|
|
2022-08-13 03:42:58 +00:00
|
|
|
return user ? <UserPage user={user} /> : <Custom404 />
|
2021-12-16 00:52:19 +00:00
|
|
|
}
|