@cocalc/database
Version:
CoCalc: code for working with our PostgreSQL database
42 lines • 1.76 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEmailExclusiveSSO = void 0;
const get_strategies_1 = __importDefault(require("@cocalc/server/auth/sso/get-strategies"));
const check_required_sso_1 = require("@cocalc/server/auth/sso/check-required-sso");
async function checkEmailExclusiveSSO(db, account_id, new_email_address, cb) {
try {
const strategies = await (0, get_strategies_1.default)();
// user's cannot change their email address to one that's covered by an exclusive strategy
if ((0, check_required_sso_1.checkRequiredSSO)({ strategies, email: new_email_address }) != null) {
cb(null, true);
return;
}
// user's current email: not allowed to modify it if covered by an exclusive strategy
const emailQuery = await db.async_query({
query: "SELECT email_address FROM accounts",
where: { "account_id = $": account_id },
});
const email = emailQuery.rows[0].email_address;
if (email != null) {
const strategy = (0, check_required_sso_1.checkRequiredSSO)({ strategies, email });
if (strategy != null) {
cb(null, true);
return;
}
}
}
catch (err) {
cb(err);
return;
}
cb(null, false);
}
exports.checkEmailExclusiveSSO = checkEmailExclusiveSSO;
//# sourceMappingURL=check-email-exclusive-sso.js.map