feat: redirect preview address for visitor

This commit is contained in:
DIYgod 2023-03-05 16:09:02 +00:00
parent 2abf9f3525
commit 90d5082e24
No known key found for this signature in database
1 changed files with 14 additions and 0 deletions

View File

@ -8,6 +8,8 @@ import { GetServerSideProps } from "next"
import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server"
import { serverSidePropsHandler } from "~/lib/server-side-props"
import { QueryClient } from "@tanstack/react-query"
import { useUserRole } from "~/hooks/useUserRole"
import { getDefaultSlug, getSiteLink } from "~/lib/helpers"
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
async (ctx) => {
@ -35,6 +37,7 @@ function SitePagePage() {
const router = useRouter()
const domainOrSubdomain = router.query.site as string
const pageSlug = router.query.page as string
const userRole = useUserRole(domainOrSubdomain)
const page = useGetPage({
site: domainOrSubdomain,
@ -43,6 +46,17 @@ function SitePagePage() {
const site = useGetSite(domainOrSubdomain)
if (userRole.isSuccess && !userRole.data && page.isSuccess) {
router.push(
`${getSiteLink({
subdomain: domainOrSubdomain,
})}/${
page.data?.slug ||
getDefaultSlug(page.data?.title || "", page.data?.id || "")
}`,
)
}
return (
<SitePage
page={