''next-session' is not working with 'connect-pg-simple'

Documentation or an example on 'next-session' on how to connect it to Postgres was very dry.

Following the compatibility example on npm did not work.

const session = require("express-session");
const RedisStore = require("connect-redis")(session);

// Use `expressSession` from `next-session/lib/compat` as the replacement

import { expressSession } from "next-session/lib/compat";

const pgSession = require("connect-pg-simple")(expressSession)

export const getSession = nextSession({
    cookie: {
        maxAge: 432000,
    },
    store: new pgStore({...config}},
});

Error: ...failed to prune "session"



Solution 1:[1]

Not as simple as 'express-session' to get it working but it was a lot simpler than learning how to use jwt 'iron-session' library...

I managed to get it working by doing this:

import nextSession from "next-session";
import pgPool from "./db";

import { promisifyStore } from "next-session/lib/compat";
import { expressSession } from "next-session/lib/compat";

const pgSession = require("connect-pg-simple")(expressSession);

const connectStore = new pgSession({
    pool: pgPool,
    tableName: "session",
});

export const getSession = nextSession({
    cookie: {
        maxAge: 432000,
    },
    store: promisifyStore(connectStore),
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xXx_Hacker_xXx