@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
36 lines (35 loc) • 1.61 kB
JavaScript
;
/*
Similar to the public profile, but also get additional information
that shouldn't be made available to anybody who knows this account_id.
Only call this for the account_id of the signed in user.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pool_1 = __importDefault(require("@cocalc/database/pool"));
async function getPrivateProfile(account_id, noCache = false) {
const pool = (0, pool_1.default)(noCache ? undefined : "medium");
const { rows } = await pool.query("SELECT first_name, last_name, profile, name, groups, email_address, passports FROM accounts WHERE account_id=$1", [account_id]);
if (rows.length == 0) {
throw Error(`no account with id ${account_id}`);
}
const is_admin = !!rows[0].groups?.includes("admin");
// anonymous means "no email and no passport", because if you have an email address somehow,
// then you can set/reset a password... and of course we consider you "known" by having an email.
const is_anonymous = !rows[0].email_address && !rows[0].passports;
return {
account_id,
first_name: rows[0].first_name ?? "Anonymous",
last_name: rows[0].last_name ?? "User",
image: rows[0].profile?.image,
color: rows[0].profile?.color,
name: rows[0].name,
is_admin,
is_anonymous,
email_address: rows[0].email_address,
};
}
exports.default = getPrivateProfile;
//# sourceMappingURL=private.js.map