# @zanix/server-auth

> ZanixJS Framework API Server Authentication

Latest version **2.1.0** (published 2025-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zanix/server-auth
pnpm add @zanix/server-auth
yarn add @zanix/server-auth
bun add @zanix/server-auth
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2025-03-11 |
| First published | 2023-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 85.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ismael Calle - icalle@utp.edu.co |
| Maintainers | zanix-io, iscam2216 |

## Links

- npm: https://www.npmjs.com/package/@zanix/server-auth
- Repository: https://github.com/zanix-io/zjs-server-auth
- Homepage: https://github.com/zanix-io/zjs-server-auth#readme
- Issues: https://github.com/zanix-io/zjs-server-auth/issues
- npm.io page: https://npm.io/package/@zanix/server-auth

## Dependencies (3)

- [bcryptjs](https://npm.io/package/bcryptjs.md) ^2.4.3
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^9.0.2
- [@zanix/server-core](https://npm.io/package/@zanix/server-core.md) ^2.1.6

## Recent versions

- 2.1.0 (latest) — 2025-03-11
- 2.0.0 — 2024-09-25
- 2.0.0-alpha.1 — 2024-06-08
- 1.0.0-beta.5 — 2023-12-20
- 1.0.0-beta.4 — 2023-12-18
- 1.0.0-beta.3 — 2023-12-18
- 1.0.0-beta.2 — 2023-12-18
- 1.0.0-beta.1 — 2023-12-16

## README

### @zanix/server-auth

[![npm version](https://badge.fury.io/js/%40zanix%2Fserver-auth.svg)](https://badge.fury.io/js/%40zanix%2Fserver-auth) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![npm downloads](https://img.shields.io/npm/dt/%40zanix%2Fserver-auth.svg)](https://www.npmjs.com/package/@zanix/server-auth)

[![PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/ismaelcallem?country.x=CO&locale.x=es_XC)

## Table of Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
- [Support and Contributions](#support-and-contributions)
- [License](#license)
- [Author](#author)

<a name="introduction"></a>

### Introduction

`@zanix/server-auth` provides authentication decorators and JWT support, allowing seamless integration of authentication mechanisms within Node.js applications. It also introduces functionality for cyclical toggling of JWT signing keys with customizable expiration settings.

<a name="installation"></a>

### Installation

To install `@zanix/server-auth` in your project, use the following command:

```bash
npm install @zanix/server-auth
```

<a name="usage"></a>

### Usage

Utilize the provided `AuthDecorators` and `Setup` classes to incorporate authentication decorators and manage JWT tokens within your application.

`@zanix/server-auth` utilizes the following environment variables:

- **ZANIX_JWT_KMA**: JWT Keys Max AGE.
  Time format: `M` (months), `d` (days), `h` (hours, default).
  Default value: `12M`.
  _To **disable** this expiration, set it to `Inf` or `-1`._

- **ZANIX_JWT_KTCD**: Key Toggle Cycle Duration.
  Time format: `M` (months), `d` (days), `h` (hours, default).
  Default value: `30d`.
  _This value is limited to **3 times** the value of **ZANIX_JWT_KMA** to avoid session loss._

- **ZANIX_JWT_KFCT**: JWT Maximum number of Keys For Cyclical Toggling.
  Default value: `3`.
  **Note**: The `ExpiresIn` time for a generated token is limited to a quarter of **ZANIX_JWT_KMA** to avoid session loss.

<a name="support-and-contributions"></a>

### Support and Contributions

If you encounter any issues or have suggestions for improvements, please submit them in the [issue tracker](https://github.com/zanix-io/zjs-server-auth/issues).

Contributions to enhance the functionality or resolve issues are welcomed via pull requests. Ensure adherence to code standards and include appropriate test coverage.

<a name="license"></a>

### License

This module is open-source and released under the [MIT License](https://opensource.org/licenses/MIT). You are free to modify and distribute it as per the terms of the license.

<a name="authors"></a>

### Authors ✨

- Ismael Calle Marulanda [@iscam2216](https://github.com/iscam2216)

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