# @iterout/auth-module

> Auth module for node backend applications

Latest version **1.4.4** (published 2022-04-07) · ISC license · 0 weekly downloads

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

## Install

```sh
npm install @iterout/auth-module
pnpm add @iterout/auth-module
yarn add @iterout/auth-module
bun add @iterout/auth-module
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.4 |
| Published | 2022-04-07 |
| First published | 2022-03-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 7 |
| Unpacked size | 63.4 KB |
| Known vulnerabilities | 0 (+27 in 3 direct dependencies) |
| Install scripts | no |
| Author | @iterout |
| Maintainers | mattiabonardi |
| Keywords | auth |

## Links

- npm: https://www.npmjs.com/package/@iterout/auth-module
- Repository: https://github.com/mattia-bonardi-smeup/auth-module
- Homepage: https://github.com/mattia-bonardi-smeup/auth-module#readme
- Issues: https://github.com/mattia-bonardi-smeup/auth-module/issues
- npm.io page: https://npm.io/package/@iterout/auth-module

## Dependencies (7)

- [axios](https://npm.io/package/axios.md) ^0.26.1
- [bcryptjs](https://npm.io/package/bcryptjs.md) ^2.4.3
- [mongoose](https://npm.io/package/mongoose.md) ^6.2.4
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [class-validator](https://npm.io/package/class-validator.md) ^0.13.2
- [google-auth-library](https://npm.io/package/google-auth-library.md) ^7.14.0
- [@iterout/email-sender-module](https://npm.io/package/@iterout/email-sender-module.md) ^1.0.7

## 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.4.4 (latest) — 2022-04-07
- 1.4.3 — 2022-04-03
- 1.4.2 — 2022-04-03
- 1.4.1 — 2022-04-03
- 1.4.0 — 2022-04-03
- 1.3.3 — 2022-04-03
- 1.3.2 — 2022-03-31
- 1.3.1 — 2022-03-31
- 1.3.0 — 2022-03-28
- 1.2.9 — 2022-03-24
- 1.2.8 — 2022-03-24
- 1.2.7 — 2022-03-24
- 1.2.6 — 2022-03-24
- 1.2.5 — 2022-03-24
- 1.2.4 — 2022-03-20
- … 16 more at https://npm.io/package/@iterout/auth-module/versions

## README

# Auth Module

Auth module for node.js backend applications

## Installation

```
npm install @iterout/auth-module
```

## Configuration

To use correctly the auth-module you must configure:

- Email service
- Jwt service (optional)

```typescript
import { configureAuth } from "@iterout/auth-module";
import { createEmailConfig } from "@iterout/email-sender-module";
import { join } from "path";

// create auth email configuration
const authEmailConfig: EmailConfig = createEmailConfig(
  [
    join(process.cwd(), [MAIL_TEMPLATE_DIR],
    join(process.cwd(), "node_modules", "@iterout", "auth-module", "mail_templates")
  ],
  [EMAIL_SENDER],
  [EMAIL_SENDER_PASSWORD],
  [EMAIL_SERVICE]
)

// configure auth module
configureAuth(
  authEmailConfig,
  [FRONTEND_URL],
  [JWT_SECRET], //optional
  [JWT_ACCESS_TOKEN_DURATION], //optional
  [JWT_REFRESH_TOKEN_DURATION] //optional
)
```

## Functions

### Login

Verify user credential to mongodb and retrun authorizations tokens

```typescript
login(authData: AuthData): Promise<TokenData>
```

### Logout

Clear and return tokens

```typescript
logout(): Promise<TokenData>
```

### Registration

Check and save user to mongodb

```typescript
registration(user: User)
```

### ConfirmSignIn

Confirm user registration. Set isActive = true

```typescript
confirmSignIn(userId: string)
```

### RefreshToken

Check refreshToken and return new accessToken

```typescript
refreshToken(refreshToken: string): Promise<TokenData>
```

## authorizeUser

Check accessToken, and user roles

```typescript
authorizeUser(accessToken: string, ...roles: string[]): Promise<User>
```

## getUserById

Getting user info (password will be blank)

```typescript
getUserById(userId: string)
```

## deleteUser

Delete user

```typescript
deleteUser(userId: string)
```

## updateUser

Update user

```typescript
updateUser(userUpdated: User)
```

## Utils

### createEmptyUser

Create empty user

```typescript
createEmptyUser(): User
```

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