Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@types/passport-local
Advanced tools
TypeScript definitions for passport-local
@types/passport-local provides TypeScript type definitions for the passport-local strategy, which is a Passport.js strategy for authenticating with a username and password.
LocalStrategy
This feature allows you to define a local authentication strategy using a username and password. The code sample demonstrates how to set up the LocalStrategy with Passport.js.
const LocalStrategy = require('passport-local').Strategy;
const passport = require('passport');
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, { message: 'Incorrect username.' }); }
if (!user.validPassword(password)) { return done(null, false, { message: 'Incorrect password.' }); }
return done(null, user);
});
}
));
Serialization and Deserialization
This feature allows you to serialize and deserialize user information to maintain authentication state across HTTP requests. The code sample shows how to implement these methods with Passport.js.
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
Middleware Integration
This feature allows you to integrate Passport.js middleware into an Express application. The code sample demonstrates how to set up session management and authentication routes.
const express = require('express');
const passport = require('passport');
const app = express();
app.use(require('express-session')({ secret: 'secret', resave: false, saveUninitialized: false }));
app.use(passport.initialize());
app.use(passport.session());
app.post('/login', passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' }));
@types/passport provides TypeScript type definitions for the core Passport.js library. It is essential for adding type safety to your Passport.js authentication strategies and middleware.
@types/passport-jwt provides TypeScript type definitions for the passport-jwt strategy, which is used for authenticating with JSON Web Tokens (JWT). It is useful for applications that use token-based authentication instead of session-based.
@types/passport-google-oauth20 provides TypeScript type definitions for the passport-google-oauth20 strategy, which is used for authenticating with Google OAuth 2.0. It is useful for applications that want to allow users to log in using their Google accounts.
npm install --save @types/passport-local
This package contains type definitions for passport-local (https://github.com/jaredhanson/passport-local).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/passport-local.
/// <reference types="passport"/>
import { Strategy as PassportStrategy } from "passport-strategy";
import express = require("express");
interface IStrategyOptions {
usernameField?: string | undefined;
passwordField?: string | undefined;
session?: boolean | undefined;
passReqToCallback?: false | undefined;
}
interface IStrategyOptionsWithRequest {
usernameField?: string | undefined;
passwordField?: string | undefined;
session?: boolean | undefined;
passReqToCallback: true;
}
interface IVerifyOptions {
message: string;
}
interface VerifyFunctionWithRequest {
(
req: express.Request,
username: string,
password: string,
done: (error: any, user?: Express.User | false, options?: IVerifyOptions) => void,
): void;
}
interface VerifyFunction {
(
username: string,
password: string,
done: (error: any, user?: Express.User | false, options?: IVerifyOptions) => void,
): void;
}
declare class Strategy extends PassportStrategy {
constructor(options: IStrategyOptionsWithRequest, verify: VerifyFunctionWithRequest);
constructor(options: IStrategyOptions, verify: VerifyFunction);
constructor(verify: VerifyFunction);
name: string;
}
These definitions were written by Maxime LUCE.
FAQs
TypeScript definitions for passport-local
The npm package @types/passport-local receives a total of 306,552 weekly downloads. As such, @types/passport-local popularity was classified as popular.
We found that @types/passport-local demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.