Convexpress routes to implement a user system in the lk-architecture.
Example usage with mongodb as database.
import {Kinesis} from "aws-sdk";
import convexpress from "convexpress";
import express from "express";
import getDispatch from "lk-dispatch";
import {getConvroutes, getAuthenticateMiddleware} from "lk-users-convexpress";
const dispatchEvent = getDispatch({
kinesisClient: new Kinesis(),
kinesisStream: "entrypoint",
producerId: "server@hostname"
});
const usersOptions = {
jwtSecret: new Buffer("jwtSecret"),
jwtIssuer: "jwtIssuer",
dispatchEvent: dispatchEvent,
findUserByEmail: async (email) => {
const db = await mongodb;
return db.collection("users").findOne({"emails.address": email});
},
findUserById: async (userId) => {
const db = await mongodb;
return db.collection("users").findOne({_id: userId});
},
getUserId: user => user._id,
allowSignup: false
};
const usersConvroutes = getConvroutes(usersOptions);
const authenticate = getAuthenticateMiddleware(usersOptions);
const convrouter = convexpress()
.convroute(usersConvroutes.login)
.use(authenticate)
.convroute(createUser)
.convroute(removeUser)
.convroute(addRole)
.convroute(removeRole)
.convroute(replaceProfile);
express()
.use(convrouter)
.listen(process.env.PORT);
## API
getConvroutes(options)
=> returns an object with all defined convroutesgetAuthenticateMiddleware(options)
=> returns a middleware function to authenticate requests
### options
jwtSecret
jwtIssuer
dispatchEvent
findUserByEmail
findUserById
getUserId
allowSignup
(optional)