Cookie Session Transport

const cookieTransport = require('@arangodb/foxx/sessions/transports/cookie');

The cookie transport stores session identifiers in cookies on the request andresponse object.

Examples

  1. // Pass in a secure secret from the Foxx configuration
  2. const secret = module.context.configuration.cookieSecret;
  3. const sessions = sessionsMiddleware({
  4. storage: module.context.collection('sessions'),
  5. transport: cookieTransport({
  6. name: 'FOXXSESSID',
  7. ttl: 60 * 60 * 24 * 7, // one week in seconds
  8. algorithm: 'sha256',
  9. secret: secret
  10. })
  11. });
  12. module.context.use(sessions);

Creating a transport

cookieTransport([options]): Transport

Creates a Transport that can be used in the sessions middleware.

Arguments

  • options: Object (optional)

An object with the following properties:

  • name: string (Default: "sid")

The name of the cookie.

  • ttl: number (optional)

Cookie lifetime in seconds. Note that this does not affect the storage TTL(i.e. how long the session itself is considered valid), just how long thecookie should be stored by the client.

  • algorithm: string (optional)

The algorithm used to sign and verify the cookie. If no algorithm isspecified, the cookie will not be signed or verified.See the cookie method on the response object.

  • secret: string (optional)

Secret to use for the signed cookie. Will be ignored if no algorithm is provided.

  • path: string (optional)

Path for which the cookie should be issued.

  • domain: string (optional)

Domain for which the cookie should be issued.

  • secure: boolean (Default: false)

Whether the cookie should be marked as secure (i.e. HTTPS/SSL-only).

  • httpOnly: boolean (Default: false)

Whether the cookie should be marked as HTTP-only (rather than alsoexposing it to client-side code).

If a string is passed instead of an options object, it will be interpretedas the name option.