Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eisberg-labs/next-mongoose-session

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eisberg-labs/next-mongoose-session

Enables mongodb cached session for nextjs api routes and ssr pages (static and dynamic)

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Next Mongoose Session

Enables mongodb cached session for nextjs api routes and ssr pages (static and dynamic).

Installation

npm i --save @eisberg-labs/next-mongoose-session

Usage

In pages use like:

export const getStaticProps = withMongooseSessionSSR(async function () {
}, uri, options);
// or
export const getServerSideProps = withMongooseSessionSSR(async function () {

}, uri, options);

In api routes use like:

export default withMongooseSessionApiRoute(
  async function handler(req, res) {

  }
, uri, options);

To avoid repetition when defining mongodb uri and connect options, I suggest creating another module:

import * as api from '@eisberg-labs/next-mongoose-session';

const uri = process.env.MONGODB_URI
const options = {
  bufferCommands: false
}
export function withMongooseSessionSSR<P extends { [key: string]: unknown } = { [key: string]: unknown }>(
  handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>
) {
  return api.withMongooseSessionSSR(handler, uri, options)
}

export async function withMongooseSessionApiRoute<T>(handler: NextApiHandler) {
  return api-withMongooseSessionApiRoute(handler, uri, options);
}

FAQs

Package last updated on 30 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc