# zengenti-login-package

> A package to provide login functionality to a react project using redux for state management

Latest version **0.0.7** (published 2019-11-22) · None license · 0 weekly downloads

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

## Install

```sh
npm install zengenti-login-package
pnpm add zengenti-login-package
yarn add zengenti-login-package
bun add zengenti-login-package
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2019-11-22 |
| First published | 2019-10-16 |
| Weekly downloads | 0 |
| License | None |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 751.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| Author | http://Zengenti.com |
| Maintainers | n.flatley |

## Links

- npm: https://www.npmjs.com/package/zengenti-login-package
- Repository: https://gitlab.zengenti.com/zengenti-packages/login
- npm.io page: https://npm.io/package/zengenti-login-package

## Dependencies (3)

- [js-cookie](https://npm.io/package/js-cookie.md) ^2.2.0
- [query-string](https://npm.io/package/query-string.md) ^5.1.1
- [zengenti-isomorphic-base](https://npm.io/package/zengenti-isomorphic-base.md) git+https://gitlab.zengenti.com/ps-projects/zengenti-base/zen-base.git#isomorphic-base

## Recent versions

- 0.0.7 (latest) — 2019-11-22
- 0.0.6 — 2019-11-21
- 0.0.5 — 2019-11-21
- 0.0.4 — 2019-11-19
- 0.0.3 — 2019-11-19
- 0.0.2 — 2019-10-16

## README

# Zengenti Login Package :lock:

A package to provide login functionality to a react project using redux for state management

Built on top of zen-base for development and testing and then published to npm as `zengenti-login-package`.

## How to use

The optimum usage of this package would be to import the reducer into your store creation script, import the sagas into your rootSaga and then wrap a dumb component export with the withLogin higher order component (HoC).

### Reducer

Importing the reducer is required to create the "user" object in the state and to persist any changes to the state

```javascript
import { reducer as UserReducer } from 'zengenti-login-package';

...

const store = createStore({ ...otherReducers, user: UserReducer }, initialState, middleware);
```

### Saga

The saga is required so the user sagas are tracked and executed in the application when actions are triggered

```javascript
import { sagas as userSagas } from 'zengenti-login-package';

...

yield all([...appSagas, ...userSagas]);
```

### withLogin HoC

Use the higher order component to provide props to your own dumb login controls. Your controls will have access to the props provided in the snippet below. It is up to you how you use these functions to build and present your components in your app.

```javascript
import { withLogin } from 'zengenti-login-package';

const MyLoginControl = ({user, loginUser, logoutUser}) => {
  return (<SomeComponents />);
};

MyLoginControl.propTypes = {
  loginUser: PropTypes.func,
  logoutUser: PropTypes.func,
  user: PropTypes.object,
};

export default withLogin(MyLoginControl);
```

### Actions

If you need to you can call user authentication actions from backend code

```javascript
import { actions as user } from 'zengenti-login-package';

store.dispatch(user.validateUser()); // read any auth cookies and log the user in if valid

store.dispatch(user.loginUser('testuser', 'password')); // authenticate the user with the provided credentials
```

### Types

Only import redux types if you need to use them in your app, for example for firing an unrelated saga based on subscribing to a specific action type triggered by the package

```javascript
import { types as USER } from 'zengenti-login-package';

export const otherSaga = [takeEvery(USER.LOGOUT_USER, resetSearch)]
```

## Global Variable dependency

Your application must provide a global variable called `SERVERS` which contains an entry called `cms`, which will provide the full CMS uri to the package's backend code so it can call the appropriate authentication API

## Example

A working example can be found in a branch of the `zen-base` repo: <https://gitlab.zengenti.com/ps-projects/zengenti-base/zen-base/tree/login-package-example>

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