Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@types/passport
Advanced tools
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.
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);
});
}
));
Provides TypeScript definitions for Express session middleware, similar to how @types/passport provides definitions for Passport.js. While @types/express-session focuses on session handling, @types/passport focuses on user authentication.
Offers TypeScript definitions for the jsonwebtoken package, which is used for generating JWTs for authentication purposes. It complements @types/passport by providing types for handling JWTs, whereas @types/passport is more broadly focused on authentication strategies.
npm install --save @types/passport
This package contains type definitions for Passport (http://passportjs.org).
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/passport
Additional Details
These definitions were written by Horiuchi_H https://github.com/horiuchi, Eric Naeseth https://github.com/enaeseth.
FAQs
TypeScript definitions for passport
The npm package @types/passport receives a total of 1,072,096 weekly downloads. As such, @types/passport popularity was classified as popular.
We found that @types/passport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.