Skip to content

Releases: hoangvvo/next-session

v4.0.3

17 Nov 14:20
Compare
Choose a tag to compare
  • Correct to set cookie.httpOnly option to false (#354)

v4.0.2

22 Sep 11:26
Compare
Choose a tag to compare
  • Fix build for ES2020 features

v4.0.1

22 Sep 11:05
Compare
Choose a tag to compare
  • Remove class-properties from MemoryStore (#352)

v4.0.0

22 Sep 10:56
Compare
Choose a tag to compare
  • ESM support, more lightweight
  • More reliable due to removal of troublesome features like dual-getInitialProps/api support, callback/promise store dual support, etc.
  • Add session.touch()

note: v3 is continued to be maintained with bug fixes.

Breaking changes

session.isNew is removed

You can check the number of keys in session to determined if it is new or set a custom property to your session

const isNew = Object.keys(req.session) > 1; // req.session only has the `cookie` property if new
// OR
req.session.isNotNew = true;

touchAfter is now in seconds and not miliseconds

// BEFORE
const options = {
  touchAfter: 7 * 24 * 60 * 60 * 1000, // 1 week
};

// AFTER
const options = {
  touchAfter: 7 * 24 * 60 * 60, // 1 week
};

remove useSession, applySession, and withSession in favor of a factory nextSession() method

// BEFORE
import { withSession, applySession, session } from "next-session";
withSession(handler, options);
applySession(req, res, options);
app.use(session(options));

// AFTER
import nextSession from "next-session";
const getSession = nextSession(options);

The returned getSession is almost the same with applySession, only without the options props. You can also re-implement withSession and session like below:

const getSession = nextSession(options);

function withSession(handler) {
  return async function handlerWithSession(req, res) {
    await getSession(req, res);
    return handler(req, res);
  };
}

async function session(req, res, next) {
  try {
    await getSession(req, res);
    next();
  } catch (err) {
    next(err);
  }
}

connect store requires promisification

In version v3.3.0, we remove the need to use promisifyStore with connect/express session store. After reconsideration on perf and reliability, this is added back.

Also, both promisifyStore and expressSession are moved to next-session/lib/compat for better bundle size if not used.

// BEFORE
import { expressSession } from "next-session";
const RedisStore = require("connect-redis")(expressSession);

const options = {
  store: new RedisStore(),
};

// AFTER
import { expressSession, promisifyStore } from "next-session/lib/compat";
const RedisStore = require("connect-redis")(expressSession);

const options = {
  store: promisifyStore(new RedisStore()),
};

v3.4.3

20 Sep 17:33
Compare
Choose a tag to compare
  • Should not set cookie if session is not populated (#349)

v3.4.2

20 Sep 12:21
Compare
Choose a tag to compare
  • Avoid modifying options.store to create compat layer (#343)
  • Bump deps and fix integration tests (#344)
  • Remove event emitter from store (#347)
  • Make implementation cleaner (#348)

v3.4.1

19 Sep 10:52
Compare
Choose a tag to compare
  • Clean up and fix potential issue when calling res.end in autoCommit mode

v3.4.0

25 Nov 04:27
Compare
Choose a tag to compare
  • Refactor, remove rolling option and fix unreliable tests (#283)
  • Avoid override set-cookie (#320)

v3.3.2

14 Sep 12:01
Compare
Choose a tag to compare
  • Fix cookie expiry. (Fix #280)

v3.3.1

02 Sep 09:00
Compare
Choose a tag to compare
  • Fix callback store support (#273)
  • Set cookie properly 🤦