forked from tsai/budibase
4 changed files with 30 additions and 23 deletions
@ -1,14 +1,10 @@ |
|||||
const Router = require("@koa/router") |
const Router = require("@koa/router") |
||||
const controller = require("../controllers/auth") |
const controller = require("../controllers/auth") |
||||
const authorized = require("../../middleware/authorized") |
|
||||
const { BUILDER } = require("../../utilities/security/permissions") |
|
||||
|
|
||||
const router = Router() |
const router = Router() |
||||
|
|
||||
|
// TODO: needs removed
|
||||
router.post("/api/authenticate", controller.authenticate) |
router.post("/api/authenticate", controller.authenticate) |
||||
// TODO: this is a hack simply to make sure builder has a cookie until auth reworked
|
|
||||
// router.post("/api/builder/login", authorized(BUILDER), controller.builderLogin)
|
|
||||
// doesn't need authorization as can only fetch info about self
|
|
||||
router.get("/api/self", controller.fetchSelf) |
router.get("/api/self", controller.fetchSelf) |
||||
|
|
||||
module.exports = router |
module.exports = router |
||||
|
|||||
@ -0,0 +1,21 @@ |
|||||
|
const CouchDB = require("../../db") |
||||
|
const { |
||||
|
generateUserMetadataID, |
||||
|
getEmailFromUserMetadataID, |
||||
|
} = require("../db/utils") |
||||
|
const { getGlobalUsers } = require("../../utilities/workerRequests") |
||||
|
|
||||
|
exports.getFullUser = async ({ ctx, email, userId }) => { |
||||
|
if (!email) { |
||||
|
email = getEmailFromUserMetadataID(userId) |
||||
|
} |
||||
|
const db = new CouchDB(ctx.appId) |
||||
|
const global = await getGlobalUsers(ctx, ctx.appId, email) |
||||
|
const user = await db.get(generateUserMetadataID(email)) |
||||
|
return { |
||||
|
...global, |
||||
|
...user, |
||||
|
// make sure the ID is always a local ID, not a global one
|
||||
|
_id: generateUserMetadataID(email), |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue