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

@types/passport-jwt

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/passport-jwt

TypeScript definitions for passport-jwt

  • 4.0.1
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
511K
decreased by-29.19%
Maintainers
1
Weekly downloads
 
Created

What is @types/passport-jwt?

@types/passport-jwt provides TypeScript type definitions for the passport-jwt library, which is a Passport strategy for authenticating with a JSON Web Token (JWT). This package allows developers to use TypeScript's type-checking features when working with passport-jwt, ensuring better code quality and reducing runtime errors.

What are @types/passport-jwt's main functionalities?

JWT Strategy Configuration

This feature allows you to configure the JWT strategy for Passport. The code sample demonstrates how to set up the strategy with options for extracting the JWT from the authorization header and specifying the secret key.

const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const opts = {
  jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
  secretOrKey: 'your_jwt_secret'
};
passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
  User.findOne({id: jwt_payload.sub}, (err, user) => {
    if (err) {
      return done(err, false);
    }
    if (user) {
      return done(null, user);
    } else {
      return done(null, false);
    }
  });
}));

JWT Authentication Middleware

This feature allows you to protect routes using JWT authentication. The code sample shows how to use the configured JWT strategy as middleware in an Express route to protect it from unauthorized access.

const express = require('express');
const passport = require('passport');
const app = express();
app.use(passport.initialize());
app.get('/protected', passport.authenticate('jwt', { session: false }), (req, res) => {
  res.json({ message: 'You have accessed a protected route!' });
});

Other packages similar to @types/passport-jwt

FAQs

Package last updated on 26 Jan 2024

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