Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
Last active June 25, 2022 05:06
Show Gist options
  • Save ChristianOConnor/ac83419459f3fa812655517f995bf179 to your computer and use it in GitHub Desktop.
Save ChristianOConnor/ac83419459f3fa812655517f995bf179 to your computer and use it in GitHub Desktop.
TypeError: res.header is not a function 062422

This is the code:

export async function getServerSideProps({ req, res, query }) {
  const { id } = query
  const cookies = Cookies(req, res)
  const jwt = cookies.get('lit-auth')
  if (!jwt) {
    return {
      props: {
        authorized: false
      },
    }
  }

  const { verified, payload } = LitJsSdk.verifyJwt({ jwt })
  console.log(verified)
  console.log(payload)
  if (
    payload.baseUrl !== "http://localhost:3000"
    //payload.baseUrl !== "https://nextjs-lit-gating-for-unity.vercel.app"
    || payload.path !== '/protected'
    || payload.extraData !== id
  ) {
    return {
      props: {
        authorized: false
      },
    }
  }

  res.header(`set-cookie: lit_protocols_jwt=${payload}; max-age=2592000`);

  return {
    props: {
      authorized: verified ? true : false
    },
  }
}

#This is the error:

TypeError: res.header is not a function
  187 |   }
  188 | 
> 189 |   res.header(`set-cookie: lit_protocols_jwt=${payload}; max-age=2592000`);
      |      ^
  190 | 
  191 |   return {
  192 |     props: {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment