# redux-auth0

> Auth0 Redux middleware

Latest version **1.0.10** (published 2018-04-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install redux-auth0
pnpm add redux-auth0
yarn add redux-auth0
bun add redux-auth0
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2018-04-19 |
| First published | 2017-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 94.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Florian Pereira |
| Maintainers | flo71099 |
| Keywords | auth0, redux, redux-auth0, authentication |

## Links

- npm: https://www.npmjs.com/package/redux-auth0
- Repository: https://github.com/flo-pereira/redux-auth0
- Homepage: https://github.com/flo-pereira/redux-auth0#readme
- Issues: https://github.com/flo-pereira/redux-auth0/issues
- npm.io page: https://npm.io/package/redux-auth0

## Dependencies (1)

- [auth0-js](https://npm.io/package/auth0-js.md) ^9.4.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

- 1.0.10 (latest) — 2018-04-19
- 1.0.9-rc — 2018-01-16
- 1.0.8-rc — 2018-01-16
- 1.0.7-rc — 2017-12-20
- 1.0.6-rc — 2017-12-20
- 1.0.5-rc — 2017-12-10
- 1.0.2-rc — 2017-12-04
- 1.0.1-rc — 2017-12-04
- 1.0.0-rc — 2017-11-28
- 0.0.1 — 2017-11-28

## README

## Redux Auth0 middleware

In the project directory, you can run:

### `yarn add redux-auth0`

(or `npm install redux-auth0`)

#### Initialise your store:

```javascript
import { combineReducers, applyMiddleware, compose } from 'redux';
import auth0 from 'redux-auth0';
````

```javascript
const { createStore: createStoreWithAuth0, middleware:auth0middleware, reducer: auth } = auth0({
  domain: 'your-domain.auth0.com',
  clientID: 'YOUR_CLIENT_ID',
  redirectUri: 'http://your-allowed/callback',
  audience: 'https://your-domain.auth0.com/userinfo',
  responseType: 'token id_token',
  scope: 'token openid',
});
```

```javascript
const middlewares = [/*any middleware*/, auth0middleware];
```

```javascript
//Use redux-auth0 createStore
const store = createStoreWithAuth0(
    combineReducers({
      /* any reducer */
      auth,
    }),
    compose(
      /* any enhancers */
      applyMiddleware(...middlewares),
      /*...*/
  )
);

```

### Username password authentication 
```javascript
  store.dispatch(
    loginUsernamePassword({
        username: 'john.doe@mail.com',
        password: 'password',
        realm: 'YourAuth0Database',
        
        //optional action dispatched on user login:
        redirect: {type: 'ANY_ACTION'}
    })
  );
```

### Login with google
```javascript
  store.dispatch(socialConnection({ connection: 'google-oauth2'}));
```

On social connection success, you'll be redirected to the callback url configure above,
so you have to parse the url to recover your token.

For example, with redux-first-router, you will have something like so:

```javascript
  import { handleLogin, handleAuthentication } from 'redux-auth0';
```

```javascript
const routes = {
    PRIVATE_ROUTE: '/private',
    AUTHORIZE: {
        path: '/callback',
        thunk: async (dispatch) => {
          try {
            const authResult = await handleAuthentication();
    
            dispatch(handleLogin(authResult));
            dispatch({ type: 'PRIVATE_ROUTE' });
          } catch (error) {
            /* ... */
          }
        }
      },
  }
```

[fully functional example](https://github.com/flo-pereira/redux-auth0/tree/master/exemple)

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