# @sapioweb/authentication

> `npm i @sapioweb/authentication --save`

Latest version **1.2.4** (published 2020-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sapioweb/authentication
pnpm add @sapioweb/authentication
yarn add @sapioweb/authentication
bun add @sapioweb/authentication
```

## 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.2.4 |
| Published | 2020-04-21 |
| First published | 2020-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andreas Beasley |
| Maintainers | sapiobeasley |

## Links

- npm: https://www.npmjs.com/package/@sapioweb/authentication
- Repository: https://github.com/Sapioweb/authentication
- Homepage: https://github.com/Sapioweb/authentication#readme
- Issues: https://github.com/Sapioweb/authentication/issues
- npm.io page: https://npm.io/package/@sapioweb/authentication

## Dependencies (5)

- [bcrypt](https://npm.io/package/bcrypt.md) ^4.0.1
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [typescript](https://npm.io/package/typescript.md) ^3.8.3
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1

## Recent versions

- 1.2.4 (latest) — 2020-04-21
- 1.2.3 — 2020-03-27
- 1.2.2 — 2020-03-27
- 1.2.1 — 2020-03-27
- 1.2.0 — 2020-03-26
- 1.1.0 — 2020-03-26
- 1.0.7 — 2020-03-25
- 1.0.6 — 2020-03-25
- 1.0.5 — 2020-03-25
- 1.0.4 — 2020-03-25
- 1.0.3 — 2020-03-25
- 1.0.2 — 2020-03-25
- 1.0.1 — 2020-03-25
- 1.0.0 — 2020-03-25

## README

## Installation

`npm i @sapioweb/authentication --save`

Basic authentication for a very simple use of logging in and registering users with their email and password. Currently there is no expansion of schemas but there are a few required validation checks baked in which are listed below.  

validateEmail()
```text
Must be an email format
```
uniqueEmail()
```text
Email will be required to be unique
```
validatePassword()
 ```
Must contain at least 1 lowercase alphabetical character.
Must contain at least 1 uppercase alphabetical character.
Must contain at least 1 numeric character.
Must contain at least one special character, but we are escaping reserved RegEx characters to avoid conflict.
Must be eight characters or longer.
```

### Setup
Wherever you may be including you environment variables, you will need to add `JWT_SECRET` with any random value you prefer.

First things first, be sure you have a connection to mongoDB already established as well as body parser to handle incoming json payloads. All other configuations you may think of are to your liking.
```typescript
config();

app.use(json());

connect(<string>process.env.CONNECTION_STRING, {
  useNewUrlParser: true,
  useUnifiedTopology: true
}).then(() => console.log('DB Connected'))
  .catch(() => console.log('Error connecting DB'));

app.use('', router);

app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
  if (res.headersSent) {
    return next(err)
  }

  return res.json({
    success: false,
    message: err.message,
    payload: req.body
  })
});

app.listen(3000, () => console.log('http://localhost:3000'));

```

You may name your routes however you may please, however be mindful of the usage of the two authentication methods for logging in and registering.
```typescript
const router = Router();

// Mount routes
router.post('/login', login);
router.post('/register', register);

export { router }
```

Following object displays the only allowed keys in order for requests to work.
```typescript
interface IUser {
  email: string;
  password: string;
}
```

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