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

next-session

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-session - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

20

lib/index.js

@@ -6,6 +6,8 @@ "use strict";

});
exports.default = void 0;
exports.default = exports.useSession = void 0;
var _crypto = _interopRequireDefault(require("crypto"));
var _cookie = require("cookie");
var Promise = _interopRequireWildcard(require("bluebird"));

@@ -17,3 +19,3 @@

var _cookie = _interopRequireDefault(require("./session/cookie"));
var _cookie2 = _interopRequireDefault(require("./session/cookie"));

@@ -132,4 +134,16 @@ var _session = _interopRequireDefault(require("./session/session"));

const useSession = (req, res, opts) => {
if (!req) return;
if (!res) {
throw new TypeError('Res not found! If you are passing handler, use the default import.');
}
req.cookies = req.cookies || (0, _cookie.parse)(req.headers.cookie);
return session(() => null, opts)(req, res);
};
exports.useSession = useSession;
session.Store = _store.default;
session.Cookie = _cookie.default;
session.Cookie = _cookie2.default;
session.Session = _session.default;

@@ -136,0 +150,0 @@ session.MemoryStore = _memory.default;

7

package.json
{
"name": "next-session",
"version": "1.0.0",
"description": "Simple promise-based session middleware for Next.js API Routes",
"version": "1.1.0",
"description": "Simple promise-based session middleware for Next.js",
"keywords": [

@@ -20,3 +20,4 @@ "javascript",

"lint:fix": "eslint src -c .eslintrc --ext js --ignore-path .gitignore --fix",
"test": "jest --coverage --coverageReporters=text-lcov | coveralls"
"test": "jest --coverage --coverageReporters=text-lcov | coveralls",
"test:local": "jest --coverage"
},

@@ -23,0 +24,0 @@ "repository": {

@@ -5,3 +5,3 @@ # next-session

Simple *promise-based* session middleware for [Next.js](https://nextjs.org/) 9 API Routes.
Simple *promise-based* session middleware for [Next.js](https://nextjs.org/).

@@ -11,3 +11,3 @@ ## Installation

```sh
npm install --save next-session
npm install next-session
```

@@ -17,2 +17,4 @@

See a real-life usage in [nextjs-mongodb-app](https://github.com/hoangvvo/nextjs-mongodb-app).
```javascript

@@ -69,2 +71,32 @@ import session from 'next-session';

### Usage with `getInitialProps`
*This is a temporary implementation for `getInitialProps`. Please be aware that it **will** be different in the next major version.*
`next-session` may be used in `getInitialProps` by `await` calling `useSession` with arguments of `req` and `res`.
```javascript
import { useSession } from 'next-session';
const Page = () => {
// React components
}
Page.getInitialProps = async ({ req, res }) => {
await useSession(req, res);
if (req.session.views) {
// On later visits, increase # of views by one on every request
req.session.views += 1;
} else {
// On first visit, set # of views to 1
req.session.views = 1;
}
return {
views: req.session.views
}
}
```
## API
### session(handler, options)

@@ -71,0 +103,0 @@

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