[Next.js] Hide Sensitive Information from the Consumers of Next.js API

We'll learn how to use Next.js API Routes to hide sensitive information from the clients. In this case, we're calling the JSON Placeholder API with a "secret" value in the headers. All that sensitive information is hidden from the clients since they don't call, or even know, that we're calling the JSON Placeholder API under the hood.

 

async function getSuperSecretData() {
  const result = await fetch("https://jsonplaceholder.typicode.com/todos/1", {
    headers: {
      authorization: 'SUPER SECRET VALUE'
    }
  }).then(res => res.json())

  return result
}

async function handler(req, res) {
  const secretTodo = await getSuperSecretData()

  res.json({todo: secretTodo})
}

export default handler

authorization header won't be seen from the request in backend

 

posted @ 2022-04-03 17:39  Zhentiw  阅读(41)  评论(0编辑  收藏  举报