Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestjs/jwt

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/jwt

Nest - modern, fast, powerful node.js web framework (@jwt)

  • 9.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
581K
decreased by-42.11%
Maintainers
2
Weekly downloads
 
Created

What is @nestjs/jwt?

@nestjs/jwt is a module for NestJS that provides utilities for working with JSON Web Tokens (JWT). It allows you to easily generate, sign, and verify JWTs, which are commonly used for authentication and authorization in web applications.

What are @nestjs/jwt's main functionalities?

Generate JWT

This feature allows you to generate a JWT using a payload and a secret key. The `sign` method creates a token that can be used for authentication.

const jwt = require('@nestjs/jwt');
const jwtService = new jwt.JwtService({ secret: 'your-secret-key' });
const payload = { username: 'john_doe', sub: 1 };
const token = jwtService.sign(payload);
console.log(token);

Verify JWT

This feature allows you to verify a JWT using a secret key. The `verify` method decodes the token and checks its validity. If the token is invalid, an error is thrown.

const jwt = require('@nestjs/jwt');
const jwtService = new jwt.JwtService({ secret: 'your-secret-key' });
const token = 'your-jwt-token';
try {
  const decoded = jwtService.verify(token);
  console.log(decoded);
} catch (err) {
  console.error('Invalid token', err);
}

Decode JWT

This feature allows you to decode a JWT without verifying its signature. The `decode` method extracts the payload from the token.

const jwt = require('@nestjs/jwt');
const jwtService = new jwt.JwtService({ secret: 'your-secret-key' });
const token = 'your-jwt-token';
const decoded = jwtService.decode(token);
console.log(decoded);

Other packages similar to @nestjs/jwt

FAQs

Package last updated on 08 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc