diff --git a/auth.js b/auth.js index 6f07711..638641c 100644 --- a/auth.js +++ b/auth.js @@ -140,7 +140,7 @@ function auth (pluginOptions) { } else { if (!err && that.options.run !== 'all') { that.currentError = null - that.completeAuth() + return that.completeAuth() } that.nextAuth(err) } diff --git a/test/example-composited.js b/test/example-composited.js index 46e7cf5..df5e011 100644 --- a/test/example-composited.js +++ b/test/example-composited.js @@ -52,6 +52,7 @@ function build (opts) { } function verifyOddAsync (request, reply) { + request.verifyOddAsyncCalled = true; return new Promise((resolve, reject) => { verifyOdd(request, reply, (err) => { if (err) reject(err) @@ -61,6 +62,7 @@ function build (opts) { } function verifyBigAsync (request, reply) { + request.verifyBigAsyncCalled = true; return new Promise((resolve, reject) => { verifyBig(request, reply, (err) => { if (err) reject(err) @@ -152,6 +154,19 @@ function build (opts) { } }) + fastify.route({ + method: 'POST', + url: '/check-two-sub-arrays-or-2', + preHandler: fastify.auth([[fastify.verifyBigAsync], [fastify.verifyOddAsync]], { relation: 'or' }), + handler: (req, reply) => { + req.log.info('Auth route') + reply.send({ + verifyBigAsyncCalled: !!req.verifyBigAsyncCalled, + verifyOddAsyncCalled: !!req.verifyOddAsyncCalled, + }) + } + }) + fastify.route({ method: 'POST', url: '/check-composite-or-async', diff --git a/test/example-composited.test.js b/test/example-composited.test.js index 3460d4f..335cce5 100644 --- a/test/example-composited.test.js +++ b/test/example-composited.test.js @@ -486,6 +486,26 @@ test('Two sub-arrays Or Relation success', t => { }) }) +test('Two sub-arrays Or Relation called sequentially', t => { + t.plan(2) + + fastify.inject({ + method: 'POST', + url: '/check-two-sub-arrays-or-2', + payload: { + n: 110 + } + }, (err, res) => { + t.error(err) + const payload = JSON.parse(res.payload) + + t.same(payload, { + verifyBigAsyncCalled: true, + verifyOddAsyncCalled: false, + }) + }) +}) + test('Two sub-arrays Or Relation fail', t => { t.plan(2)