# passport-custom

> Custom authentication strategy for Passport.

Latest version **1.2.1** (published 2026-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install passport-custom
pnpm add passport-custom
yarn add passport-custom
bun add passport-custom
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-07-24 |
| First published | 2014-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 3 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 103 |
| Author | Mike Bell |
| Maintainers | mbell8903 |
| Keywords | passport, custom, auth, authn, authentication |

## Links

- npm: https://www.npmjs.com/package/passport-custom
- Repository: https://github.com/mbell8903/passport-custom
- Issues: https://github.com/mbell8903/passport-custom/issues
- npm.io page: https://npm.io/package/passport-custom

## Dependencies (3)

- [@types/express](https://npm.io/package/@types/express.md) ^5.0.6
- [@types/passport](https://npm.io/package/@types/passport.md) ^1.0.17
- [passport-strategy](https://npm.io/package/passport-strategy.md) ^1.0.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2026-07-24
- 1.2.0 — 2026-07-23
- 1.1.1 — 2020-02-12
- 1.1.0 — 2019-08-29
- 1.0.5 — 2015-12-03
- 1.0.1 — 2015-02-24
- 1.0.0 — 2014-09-19

## README

# passport-custom

[![Build](https://github.com/mbell8903/passport-custom/actions/workflows/publish.yml/badge.svg)](https://github.com/mbell8903/passport-custom/actions/workflows/publish.yml)

[Passport](https://www.passportjs.org/) strategy for authenticating with custom logic.

This module lets you authenticate using custom logic in your Node.js
applications. It is based on the `passport-local` module by Jared Hanson.
By plugging into Passport, custom authentication can be easily and
unobtrusively integrated into any application or framework that supports
[Connect](https://github.com/senchalabs/connect)-style middleware, including
[Express](https://expressjs.com/).

## Install

```shell
npm install passport-custom
```

## Usage

### Configure a strategy

The strategy requires a `verify` callback containing your authentication logic.
The request is always passed as the first argument. Call `done` with an error,
the authenticated user, and optional authentication information.

```js
const passport = require('passport');
const CustomStrategy = require('passport-custom').Strategy;

passport.use(new CustomStrategy(
  function(req, done) {
    User.findOne({
      username: req.body.username
    }, function (err, user) {
      done(err, user);
    });
  }
));
```

To explicitly pass Passport authentication options to the verify callback, set
`passOptionsToCallback` when constructing the strategy:

```js
passport.use(new CustomStrategy(
  { passOptionsToCallback: true },
  function(req, options, done) {
    // Use request-specific authentication options here.
    done(null, user);
  }
));
```

### Authenticate requests

Use `passport.authenticate()` with the `custom` strategy, or the name supplied
when registering the strategy.

For example, as route middleware in an [Express](https://expressjs.com/)
application:

```js
app.post('/login',
  passport.authenticate('custom', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  }
);
```

## Tests

```shell
npm install
npm test
npm run typecheck
npm run typecheck:pack
npm run coverage
```

Continuous integration enforces 100% line and function coverage and 90% branch
coverage on Node.js 24. It also validates the TypeScript declarations from both
the repository and an isolated packed consumer, and checks the expected npm
package contents.

## Credits

- [Mike Bell](https://github.com/mbell8903)

## License

[MIT](LICENSE)

Copyright (c) 2014-present Mike Bell

---
_Source: https://npm.io/package/passport-custom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
