"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "authModule", {
    enumerable: true,
    get: function() {
        return authModule;
    }
});
const _express = /*#__PURE__*/ _interop_require_default(require("express"));
const _expressasynchandler = /*#__PURE__*/ _interop_require_default(require("express-async-handler"));
const _middleware = require("@tamanu/shared/permissions/middleware");
const _convertDbRecord = require("../convertDbRecord");
const _changePassword = require("./changePassword");
const _resetPassword = require("./resetPassword");
const _login = require("./login");
const _refresh = require("./refresh");
const _setFacility = require("./setFacility");
const _userMiddleware = require("./userMiddleware");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const passthrough = (_req, _res, next)=>next();
const authModule = ({ authLimiter } = {})=>{
    const limiter = authLimiter ?? passthrough;
    const router = _express.default.Router();
    router.use('/resetPassword', limiter, _resetPassword.resetPassword);
    router.use('/changePassword', limiter, _changePassword.changePassword);
    router.post('/login', limiter, _login.login);
    router.post('/refresh', limiter, _refresh.refresh);
    router.use(_userMiddleware.userMiddleware);
    router.post('/setFacility', _setFacility.setFacility);
    router.get('/user/me', _userMiddleware.userInfo);
    router.get('/permissions', (0, _expressasynchandler.default)(_middleware.getPermissions));
    router.get('/whoami', (0, _expressasynchandler.default)((req, res)=>{
        res.send((0, _convertDbRecord.convertFromDbRecord)(req.user).data);
    }));
    return router;
};

//# sourceMappingURL=index.js.map