Skip to content

Commit

Permalink
- Breaking change: Stop supporting older behavior against layers of a…
Browse files Browse the repository at this point in the history
…rity one or two

    (will now drop one with no `done`)
- Breaking change: We now catch errors within layers so as to support more
    intuitive passing of errors (when synchronous)
- Breaking change: No longer throws when login is missing a callback (as may use as Promise)
- Breaking change: Only return from `serializeUser`, `deserializeUser` (and `transformAuthInfo`)
    when giving a synchronous serialized result or a Promise (do not do `return done()`)
- Enhancement: Promises for `serializeUser`, `deserializeUser`, `transformAuthInfo`
    (including allowing throwing `new Error('pass')` to pass); avoid need for `done`
- Enhancement: Allow `serializeUser` or `deserializeUser` to return non-`undefined`
    value for sync behavior
- Refactoring: Return Promise from `req.logIn` and from authenticate middleware's
    `strategy.success`
- Makefile: Add missing `clean-cov`
- Testing: Add tests with `req.logIn` and `SessionStrategy` returning without `done`
    (synchronously or with Promise)
- Docs: Show example of a `LocalStrategy` using async/await
- Linting: jsdoc
- npm/Docs: Add jsdoc with script, along with static server and open-cli to open
- npm: Update devDeps
- npm: Add `test-one` script
  • Loading branch information
brettz9 committed Jun 3, 2019
1 parent fa997d8 commit f07342f
Show file tree
Hide file tree
Showing 28 changed files with 3,373 additions and 470 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
coverage/
node_modules/
var/
docs/jsdoc
11 changes: 9 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ module.exports = {
// Override ash-nazg's current preference for ESM
'plugin:node/recommended-script'
],
settings: {
polyfills: [
// Needing these for some reason to avoid an error
"Promise",
"Promise.reject",
"Promise.resolve"
]
},
overrides: [
{
files: ['test/**'],
Expand Down Expand Up @@ -61,9 +69,8 @@ module.exports = {
'no-underscore-dangle': 0,
'no-param-reassign': 0,

// Disable until implementing promises and Node version supporting
// Disable as middleware approach requires some callbacks
'promise/prefer-await-to-callbacks': 0,
'promise/prefer-await-to-then': 0,

// Disable until ready to tackle
'require-jsdoc': 0,
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ LCOVFILE = ./reports/coverage/lcov.info

MOCHAFLAGS = --require ./test/bootstrap/node

COVDIR = ./var/cov/*

view-docs:
open ./docs/index.html

view-cov:
open ./var/cov/index.html

clean-cov:
-rm -r $(COVDIR)

clean: clean-docs clean-cov
-rm -r $(REPORTSDIR)

Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ application must be configured.

```javascript
passport.use(new LocalStrategy(
function (username, password, done) {
User.findOne({ 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);
});
async function (username, password) {
let user;
try {
user = await User.findOne({ username });
} catch (err) {
throw err;
}
if (!user || !user.verifyPassword(password)) { return false; }
return user;
}
));
```
Expand All @@ -88,14 +90,13 @@ as simple as serializing the user ID, and finding the user by ID when
deserializing.

```javascript
passport.serializeUser(function (user, done) {
done(null, user.id);
passport.serializeUser(function (user) {
return user.id;
});

passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
passport.deserializeUser(async function (id) {
const user = await User.findById(id);
return user;
});
```

Expand Down
Loading

0 comments on commit f07342f

Please sign in to comment.