next-sessions
v1.0.2
Published
A simple lightweight library for session handling in Next.js applications built on top of jsonwebtoken. This library is still in the Beta phase of development and more features are to be added overtime to handle various scenarios that can occur when handl
Readme
next-sessions
A simple lightweight library for session handling in Next.js applications built on top of jsonwebtoken. This library is still in the Beta phase of development and more features are to be added overtime to handle various scenarios that can occur when handling authentication.
Installation
// NPM
npm install next-sessions
// Yarn
yarn add next-sessionsUsage
Create a Session Token
import { createSessionToken } from "next-sessions";
const token = createSessionToken({ userId: "123" });
console.log(token);
Verify a Session Token
import { verifySessionToken } from "next-sessions";
const session = verifySessionToken(token);
console.log(session);
Set Cookies
import { setCookie } from "next-sessions";
// In an API route
setCookie(res, "session", token, { maxAge: 3600 });
