@certik/encrypt-decrypt-ssr
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

Encryption/Decryption for SSR NEXT_DATA

Description

In NEXT_DATA, important data is stored in order to hydrate the page during server side rendering. We cannot remove NEXT_DATA as it is required, but it leaves us vulnerable to data crawlers and scrapers who can publically access the data. This library can be used to encrypt NEXT_DATA pageProps during getStaticProps and getServerSideProps data fetching and to decrypt it in default page components.

Install

Run the following command to install:

yarn add @certik/encrypt-decrypt-ssr

Usage

For default page component:

import { withSSRDecrypt } from "@certik/encrypt-decrypt-ssr";

// Wrap the default page component alongside the secret encrypt key to decrypt and use the encrypted NEXT_DATA page props
function PageComponent({ ... }) {
    ...
}

export default withSSRDecrypt(PageComponent);

For server side:

import { withEncryptSSR } from "@certik/encrypt-decrypt-ssr";

// Wrap getStaticProps or getServerSideProps data fetching functions
export const getStaticProps: GetStaticProps = withEncryptSSR(async () => { ... });

or

export const getServerSideProps: GetServerSideProps = withEncryptSSR(async () => { ... });

Development

Edit source code in /src directory. Support Javascript, Typescript, JSX, and TSX.

Linting and Formatting

yarn lint
yarn format

Publish

Compile source code by running:

yarn build

Then publish package:

yarn publish --access public

Readme

Keywords

none

Package Sidebar

Install

npm i @certik/encrypt-decrypt-ssr

Weekly Downloads

203

Version

1.0.13

License

MIT

Unpacked Size

25.4 kB

Total Files

25

Last publish

Collaborators

  • jindong_y
  • ziyi-zhang-1130
  • victor.wu.certik
  • boyuan.yuan.certik
  • yueqiao
  • jtlemkin