# resolve-auth

> This package provide an auth to your app.

Latest version **0.17.4** (published 2018-10-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install resolve-auth
pnpm add resolve-auth
yarn add resolve-auth
bun add resolve-auth
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.17.4 |
| Published | 2018-10-17 |
| First published | 2018-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8.10 |
| Dependencies | 1 |
| Unpacked size | 31.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 769 |
| Author | reimagined team |
| Maintainers | reimagined |
| Keywords | cqrs, eventsourcing, es, ddd |

## Links

- npm: https://www.npmjs.com/package/resolve-auth
- Repository: https://github.com/reimagined/resolve
- Homepage: https://github.com/reimagined/resolve/tree/master/packages/core/resolve-auth#readme
- Issues: https://github.com/reimagined/resolve/issues
- npm.io page: https://npm.io/package/resolve-auth

## Dependencies (1)

- [cookie](https://npm.io/package/cookie.md) ^0.3.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.17.4 (latest) — 2018-10-17
- 0.17.3 — 2018-10-12
- 0.17.2 — 2018-09-28
- 0.17.1 — 2018-09-26
- 0.17.0 — 2018-09-21
- 0.16.1 — 2018-09-19
- 0.16.0 — 2018-09-18
- 0.15.2 — 2018-09-12
- 0.15.1 — 2018-09-12
- 0.15.0 — 2018-09-11
- 0.14.4 — 2018-09-03
- 0.14.3 — 2018-08-31
- 0.14.2 — 2018-08-22
- 0.14.1 — 2018-08-22
- 0.14.0 — 2018-08-10
- … 12 more at https://npm.io/package/resolve-auth/versions

## README

# **resolve-auth**
[![npm version](https://badge.fury.io/js/resolve-auth.svg)](https://badge.fury.io/js/resolve-auth)

Provides an authentication mechanism using [Passport](http://www.passportjs.org/) authentication strategy.

## Usage

First of all, create file with your strategy and add `auth` section into `config.app.json` for your application (see [`hacker-news` example]('../../examples/hacer-news')).
Next, choose a type of authentication strategy (see [passport-local](https://github.com/jaredhanson/passport-local) or [passport-google-oauth](https://github.com/jaredhanson/passport-google-oauth for example) ) and define options of it.
Create your strategy in `strategyConstructor` function using `options`.
Return an array of tuples `{ strategy, options }` for every used route in your app.

## Examples

Here is the simple example of `local` strategy, but you can use any other [Passport](http://www.passportjs.org/) strategy similarly.

```javascript
import { Strategy } from 'passport-local'
import jwt from 'jsonwebtoken'
import jwtSecret from './jwtSecret'

const options = routes.map(({ path, method, callback }) => ({
  strategy: {
    usernameField: 'username',
    passwordField: 'username',
    successRedirect: null
  },
  route: {
    path: '/register',
    method: 'POST'
  },
  callback: async (_, username) =>
    jwt.sign(           // here fake use is created
      {                   // for user storing into db see HakerNews example
        name: username    // https://github.com/reimagined/resolve/tree/master/examples/hacker-news
      },
      jwtSecret
    )
}))

const strategyConstructor = options =>
  new Strategy(
    {
      ...options.strategy,
      passReqToCallback: true
    },
    async (req, username, password, done) => {
      try {
        done(null, await options.callback(req, username, password))
      } catch (error) {
        done(error)
      }
    }
  )

export default [{ options, strategyConstructor }]

```

![Analytics](https://ga-beacon.appspot.com/UA-118635726-1/packages-resolve-auth-readme?pixel)

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