Example of SessionStore
kennym opened this issue · 1 comments
kennym commented
Could you please provide a sample implementation of the SessionStore
? I feel like this should be in the README.
rgdigital commented
Here's an SQLite3 file-based implementation, similar to how it works in PHP -
# Add SQLite3 session store to dependencies
yarn add connect-sqlite3
// ./lib/sqlite3-store.js
import { expressSession, promisifyStore } from "next-session/lib/compat";
var SQLiteStore = require("connect-sqlite3")(expressSession);
export default new SQLiteStore({ dir: "./.session/", table: "sessions" })
// ./lib/get-session.js
import nextSession from "next-session";
import { expressSession, promisifyStore } from "next-session/lib/compat";
import SQLiteStore from './sqlite3-store'
export const getSession = nextSession({
name:'SESSION',
store: promisifyStore(SQLiteStore),
cookie: {
httpOnly: false,
path: '/',
domain: process.env.SESSION_DOMAIN, // 'localhost'
sameSite: 'Lax',
secure: false // true in production
},
});