@wdalmut/one-of

Resolve if one promise resolve or reject

Usage no npm install needed!

<script type="module">
  import wdalmutOneOf from 'https://cdn.skypack.dev/@wdalmut/one-of';
</script>

README

One Of

Build Status

npm install --save @wdalmut/one-of

A simple auth middleware to support one of many authentication methods

const auth = require('@wdalmut/mini-auth');
const token = require('@wdalmut/token-auth');
const basic = require('@wdalmut/basic-auth');
const one_of = require('@wdalmut/one-of');

app.get(
    "/",
    auth(one_of([token(from_token), basic(from_basic)]),
    homePage
);

where from_token and from_basic are simple functions that will returns a promise

const from_token = (token) => {
    return Promise.resolve({id: 1});
};

const from_basic = (username, password) => {
    return Promise.resolve({id: 1});
};

If one authentication mechanism resolve the promise the authentication is considered valid otherwise a 401 is immediately returned.