menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

micro-session

November 2, 2019 at 4:38am (Edited 5 months ago)

This is still a WIP, so please don't advertise this too much, but I've been working on a session "middleware" for micro. It currently works with at least connect-mongo. You can find it here: https://github.com/meyer9/micro-session. Pull requests are welcome and if you find a store that doesn't work, open an issue. There are some slight incompatibilities with express, but it works pretty well for now.

Usage:

import session from 'micro-session'
import MongoStore from 'connect-mongo'
const MongoSession = MongoStore(session)
const getSession = session({
secret: 'someverystringsecretstring',
store: new MongoSession({
url:"mongodb://localhost/upfunc"
}),
})
export default async (req, res) => {
let session = await getSession(req, res)
if (!session.hits) {
session.hits = 1
res.json(session.hits)
} else {
session.hits += 1
res.json(session.hits)
}
}
No messages yet
private
This channel has been archived