开发者社区> 镜像站> NPM> @accounts/express-session
@accounts/express-session
Stores the access and refresh tokens as part of the session (`express-session`), this way auth flow could be based on it.
Last updated 4 months ago by leopradel .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @accounts/express-session 
SYNC missed versions from official npm registry.

@accounts/express-session

Stores the access and refresh tokens as part of the session (express-session), this way auth flow could be based on it.

npm MIT License

Install

yarn add @accounts/express-session

Usage

import * as express from 'express';
import * as session from 'express-session';
import { Tokens } from '@accounts/types';
import AccountsSession from '@accounts/express-session';
import { accountsServer } from './setup';

const accountsSession = new AccountsSession(accountsServer, {
  user: {
    name: 'currentUser',
    resolve: (tokens: Tokens) => {
      // function that returns a user object
    }
  }
});

const app = express();

app.use(
  session({
    name: 'id',
    secret: 'secret',
    rolling: true,
    cookie: { ... }, // cookie options
  })
);

app.use(accountsSession.middleware())

app.get('/me', (req, res) => {
  const user = req.currentUser; // middleware assings a user object to `req`

  res.json(user);
});

app.post('/login', (req, res) => {
  let tokens: Tokens; // Tokens  AccountsServer

  // ... a logic to log user in

  accountsSession.set(req, tokens); // sets tokens on request so middleware can access that
});

app.get('/logout', (req, res) => {
  accountsSession.destroy(req); // destroys the session and logs user out
});

Options

user.name

Specifies the name of a property that holds a user object. For example, By using currentUser, a user object is accesible on req.currentUser.

By default it uses: user

user.resolve

Function that receives an access and a refresh tokens to resolve a user object.

(tokens: Tokens) => User | Promise<User>

By default it uses AccountsServer's API to resolve a user.

name

Specifies the name of a property that holds the Tokens. For example, By using tokens, tokens are accesible on req.tokens.

By default it uses: accounts-js-tokens

License

MIT

Current Tags

  • 0.24.1-test.13                                ...           canary (8 months ago)
  • 0.29.0                                ...           latest (4 months ago)
  • 0.30.0-alpha.1                                ...           next (3 months ago)

66 Versions

  • 0.30.0-alpha.1                                ...           3 months ago
  • 0.29.0                                ...           4 months ago
  • 0.28.0                                ...           4 months ago
  • 0.28.0-alpha.1                                ...           4 months ago
  • 0.28.0-alpha.0                                ...           6 months ago
  • 0.27.0                                ...           6 months ago
  • 0.26.0                                ...           6 months ago
  • 0.25.4                                ...           7 months ago
  • 0.25.3                                ...           7 months ago
  • 0.26.0-alpha.4                                ...           7 months ago
  • 0.26.0-alpha.3                                ...           7 months ago
  • 0.26.0-alpha.2                                ...           7 months ago
  • 0.26.0-alpha.1                                ...           7 months ago
  • 0.26.0-alpha.0                                ...           8 months ago
  • 0.25.1                                ...           8 months ago
  • 0.25.0                                ...           8 months ago
  • 0.24.1-test.13                                ...           8 months ago
  • 0.24.1-alpha.13                                ...           8 months ago
  • 0.24.1-alpha.12                                ...           8 months ago
  • 0.24.0                                ...           9 months ago
  • 0.23.0                                ...           9 months ago
  • 0.22.0                                ...           10 months ago
  • 0.21.1                                ...           10 months ago
  • 0.21.0                                ...           a year ago
  • 0.20.1                                ...           a year ago
  • 0.20.0                                ...           a year ago
  • 0.19.1-alpha.2.17                                ...           a year ago
  • 0.20.0-alpha.1.cfb0004e                                ...           a year ago
  • 0.19.0                                ...           a year ago
  • 0.18.0                                ...           a year ago
  • 0.17.0                                ...           a year ago
  • 0.16.0                                ...           a year ago
  • 0.15.0                                ...           2 years ago
  • 0.14.0                                ...           2 years ago
  • 0.13.0                                ...           2 years ago
  • 0.12.0                                ...           2 years ago
  • 0.11.2                                ...           2 years ago
  • 0.11.1                                ...           2 years ago
  • 0.9.3                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.2                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.1-alpha.1                                ...           2 years ago
  • 0.5.0-alpha.1                                ...           2 years ago
  • 0.4.0-alpha.1                                ...           2 years ago
  • 0.4.0-alpha.0                                ...           2 years ago
  • 0.3.0-beta.30                                ...           2 years ago
  • 0.3.0-beta.29                                ...           2 years ago
  • 0.3.0-beta.28                                ...           2 years ago
  • 0.3.0-beta.27                                ...           2 years ago
  • 0.3.0-beta.26                                ...           2 years ago
  • 0.3.0-beta.25                                ...           2 years ago
  • 0.3.0-beta.24                                ...           2 years ago
  • 0.3.0-beta.23                                ...           2 years ago
  • 0.3.0-beta.22                                ...           2 years ago
  • 0.3.0-beta.21                                ...           2 years ago
  • 0.3.0-beta.20                                ...           2 years ago
  • 0.3.0-beta.19                                ...           2 years ago
  • 0.3.0-beta.18                                ...           2 years ago
  • 0.1.0-beta.17                                ...           2 years ago
  • 0.1.0-beta.16                                ...           2 years ago
  • 0.1.0-beta.15                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 199
Dependencies (4)
Dev Dependencies (9)
Dependents (0)
None