Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/database/settings/get-sso-strategies.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import getPool from "@cocalc/database/pool";6import type { Strategy } from "@cocalc/util/types/sso";7import { ssoDispayedName } from "@cocalc/util/auth";89/** Returns an array of public info about strategies.10* Cached a bit so safe to call a lot.11*/12export default async function getStrategies(): Promise<Strategy[]> {13const pool = getPool("long");14// entries in "conf" were used before the "info" col existed. this is only for backwards compatibility.15const { rows } = await pool.query(`16SELECT strategy,17COALESCE(info -> 'icon', conf -> 'icon') as icon,18COALESCE(info -> 'display', conf -> 'display') as display,19COALESCE(info -> 'public', conf -> 'public') as public,20COALESCE(info -> 'exclusive_domains', conf -> 'exclusive_domains') as exclusive_domains,21COALESCE(info -> 'do_not_hide', 'false'::JSONB) as do_not_hide2223FROM passport_settings24WHERE strategy != 'site_conf'25AND COALESCE(info ->> 'disabled', conf ->> 'disabled', 'false') != 'true'`);2627return rows.map((row) => {28const display = ssoDispayedName({29display: row.display,30name: row.strategy,31});3233return {34name: row.strategy,35display,36icon: row.icon, // don't use row.strategy as a fallback icon, since that icon likely does not exist37backgroundColor: COLORS[row.strategy] ?? "",38public: row.public ?? true,39exclusiveDomains: row.exclusive_domains ?? [],40doNotHide: row.do_not_hide ?? false,41};42});43}4445export const COLORS = {46github: "#000000",47facebook: "#428bca",48google: "#dc4857",49twitter: "#55acee",50} as const;515253