Socket
Socket
Sign inDemoInstall

@types/passport

Package Overview
Dependencies
12
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/passport

TypeScript definitions for passport


Version published
Weekly downloads
1.2M
decreased by-9.78%
Maintainers
1
Install size
3.97 MB
Created
Weekly downloads
 

Package description

What is @types/passport?

The @types/passport npm package provides TypeScript type definitions for Passport.js, a popular authentication middleware for Node.js. These type definitions allow TypeScript developers to use Passport.js in their applications with the benefits of type safety and IntelliSense in their code editors.

What are @types/passport's main functionalities?

Authentication Middleware Initialization

This code initializes Passport as middleware in an Express application, enabling authentication functionalities.

import * as passport from 'passport';
app.use(passport.initialize());

Serialize User

This function defines how to store the user in the session storage, typically saving the user ID.

passport.serializeUser((user, done) => {
  done(null, user.id);
});

Deserialize User

This function defines how to retrieve the user from the session storage, using the user ID to fetch the user record from the database.

passport.deserializeUser((id, done) => {
  User.findById(id, (err, user) => {
    done(err, user);
  });
});

Use of Strategy

This code sample demonstrates how to implement a local authentication strategy using Passport.js. It involves checking the username and password against stored records.

import { Strategy as LocalStrategy } from 'passport-local';
passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(password)) { return done(null, false); }
      return done(null, user);
    });
  }
));

Other packages similar to @types/passport

Readme

Source

Installation

npm install --save @types/passport

Summary

This package contains type definitions for passport (http://passportjs.org).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/passport.

Additional Details

  • Last updated: Mon, 20 Nov 2023 23:36:24 GMT
  • Dependencies: @types/express

Credits

These definitions were written by Horiuchi_H, Eric Naeseth, Igor Belagorudsky, Tomek Łaziuk, Daniel Perez Alvarez, Kevin Stiehl, and Oleg Vaskevich.

FAQs

Last updated on 21 Nov 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc