# rendr-session

> Session support for Rendr apps

Latest version **0.0.1** (published 2015-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install rendr-session
pnpm add rendr-session
yarn add rendr-session
bun add rendr-session
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-09-01 |
| First published | 2015-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chris Wang |
| Maintainers | crwang |
| Keywords | rendr, sessions |

## Links

- npm: https://www.npmjs.com/package/rendr-session
- Repository: https://github.com/crwang/rendr-session
- Homepage: https://github.com/crwang/rendr-session#readme
- Issues: https://github.com/crwang/rendr-session/issues
- npm.io page: https://npm.io/package/rendr-session

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) ^1.8.2

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2015-09-01

## README

Provides sessions for Rendr that are accessible from both the server and the client.

## How it Works

Adds methods to app.js

## Setup

### Set up the server and middleware for the sessions.

index.js

```js

// Add the require
var express = require('express'),
    rendrSession = require('rendr-session'),
    customApiProxy = require('rendr-api-proxy-optionable'),
    session = require('express-session'),
    cookieParser = require('cookie-parser'),
    ...

// Add the express session
app.use(session({
    secret: "This should be a secret in config",
    resave: false,
    saveUninitialized: true
}));

// Add the cookie parser
app.use(cookieParser("This should be a secret in config"));

var dataAdapterConfig = {
    default: {
        host: 'localhost:3000', // put your default here
        protocol: 'http'
    },
    session: {
        host: 'localhost:3030', // an example of local here
        protocol: 'http',
        headerPassthrough: { // pass through cookies for session purposes
            request: [
                'cookie'
            ]
        }
    }
};

// Use the custom api proxy or some other rest adapter to make sure the cookies get passed in
var server = rendr.createServer({
    dataAdapterConfig: dataAdapterConfig,
    apiProxy: customApiProxy
});

// Add the rendrSession middleware
server.configure(function(rendrExpressApp) {

    // Set the config into the app
    rendrSession(rendrExpressApp);
    ...
```


### Subclass from the rendrSession App

app/app.js

```js
var BaseApp = require('rendr-session/shared/app'),
    ...
    handlebarsHelpers = require('./lib/handlebarsHelpers');

```

## Usage

### New App Methods

#### app.getSessionModel()

Retrieves the session information in a backbone model.

#### app.getSessionValue(key)

Retrieves the value of a session attribute by key.

#### app.saveSession(newSessionData, callback)

Saves the new session data into a session.  newSessionData should be a json object.

### Example: Call from view or other code.

```js
// Save the data
this.app.saveSession({testText: text});
```

```js
var testText = this.app.getSessionValue('testText');
var sessionModel = this.app.getSessionModel();
```


## Tests

To run the tests, run `npm test` from the command-line.

---
_Source: https://npm.io/package/rendr-session · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
