@certik/encrypt-decrypt-ssr
v1.0.13
Published
Package for server side props encryption in Next.js
Downloads
1,132
Keywords
Readme
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