return 404 for nonexistant users and items

This commit is contained in:
keyan 2021-10-26 16:31:39 -05:00
parent 744f9d3560
commit 945225d205
4 changed files with 5 additions and 5 deletions

View File

@ -25,7 +25,7 @@ export default async function getSSRApolloClient (req) {
})
}
export function getGetServerSideProps (query, variables = null) {
export function getGetServerSideProps (query, variables = null, foundField) {
return async function ({ req, params }) {
const client = await getSSRApolloClient(req)
const { error, data } = await client.query({
@ -33,7 +33,7 @@ export function getGetServerSideProps (query, variables = null) {
variables: { ...params, ...variables }
})
if (error || !data) {
if (error || !data || (foundField && !data[foundField])) {
return {
notFound: true
}

View File

@ -15,7 +15,7 @@ import { USER_FULL } from '../../fragments/users'
import { ITEM_FIELDS } from '../../fragments/items'
import { getGetServerSideProps } from '../../api/ssrApollo'
export const getServerSideProps = getGetServerSideProps(USER_FULL)
export const getServerSideProps = getGetServerSideProps(USER_FULL, null, 'user')
const BioSchema = Yup.object({
bio: Yup.string().required('required').trim()

View File

@ -4,7 +4,7 @@ import { DiscussionForm } from '../../../components/discussion-form'
import { LinkForm } from '../../../components/link-form'
import LayoutCenter from '../../../components/layout-center'
export const getServerSideProps = getGetServerSideProps(ITEM)
export const getServerSideProps = getGetServerSideProps(ITEM, null, 'item')
export default function PostEdit ({ data: { item } }) {
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000

View File

@ -5,7 +5,7 @@ import ItemFull from '../../../components/item-full'
import { getGetServerSideProps } from '../../../api/ssrApollo'
import { useQuery } from '@apollo/client'
export const getServerSideProps = getGetServerSideProps(ITEM_FULL)
export const getServerSideProps = getGetServerSideProps(ITEM_FULL, null, 'item')
export default function AnItem ({ data: { item } }) {
const { data } = useQuery(ITEM_FULL, {