morethanmin / morethan-log

😎 A static blog using notion database
https://morethan-log.vercel.app
MIT License
1.96k stars 1.58k forks source link

[Bug]: getStaticProps function returns undefined when it makes Exception #121

Open Octoping925 opened 1 year ago

Octoping925 commented 1 year ago

Describe the bug

getStaticProps function (index.tsx) returns unexpected undefined when it makes Exception.

it cause Error: Your getStaticProps function did not return an object. Did you forget to add a return? Error

I fixed it like this.

export async function getStaticProps() {
  try {
    const posts = await getPosts()
    const filteredPost = filterPosts(posts)
    const tags = getAllTagsFromPosts(filteredPost)
    return {
      props: {
        tags: {
          All: filteredPost.length,
          ...tags,
        },
        posts: filteredPost,
      },
      revalidate: 1,
    }
  } catch (error) {
    // returns StaticProps about meaning no posts were fetched
    return {
      props: {
        tags: {
          All: 0,
        },
        posts: [],
      },
      revalidate: 1,
    }
  }
}

However, I left this bug as an issue without PR because I thought it might have been intended.

To reproduce

  1. just run yarn dev with no modification of code
  2. See error

image

Browser

Google Chrome

Validations

bocarw121 commented 1 year ago

I was having the same issue, it's because the client is making a request to a notion page that is set to private.

Choose whichever option you prefer:

Option 1. Make the page public

  1. Go to your notion page
  2. On the top right corner click on share
  3. Toggle the share to the web and you'll be good to go.

Option 2 Add an auth token to the request

  1. Follow the steps directly from React Notion private-pages

Take care!