Skip to content

Cookie-based sessions module for the Opine web framework.

License

Notifications You must be signed in to change notification settings

xyzshantaram/opine-sessions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opine-sessions

Cookie-based sessions module for the Opine web framework.

(Unafilliated with Opine's maintainers.)

Usage

Import the module

import sessions from "https://deno.land/x/opine_sessions@1.0.2/mod.ts";

Initialise

const app = opine();
sessions.init(app);

By default, this module will use x/sqlite to store data in an SQLite database. However, you can use a storage solution of your choice by passing an instance of a class that implements the Store interface.

import sessions from "https://deno.land/x/sessions@1.0.0/mod.ts";
import { Store } from "https://deno.land/x/sessions@1.0.0/mod.ts";

class CustomStore implements Store {
  /* implementation */
}

sessions.init(app, {
  store: new CustomStore(),
});

Using sessions

Get a session object by calling getClient() and use its methods:

app.get("/", (req, res) => {
  const session = sessions.getClient(req, res);
  const name = session.get<string>("name");
  session.set("name", "shantaram");
  session.delete("shantaram");

  session.set("website", "shantaram.xyz");
  session.clear();
});

For a more complete example, see examples/greeting.ts.

License

Copyright © 2022 Siddharth Singh, under the terms of the MIT License.

About

Cookie-based sessions module for the Opine web framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published