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/next/pages/api/v2/accounts/set-email-address.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Set email address for an existing account.78You must include both the email address and password. If there is no password9currently set for the account, you have to set one as part of this request.10*/1112import setEmailAddress from "@cocalc/server/accounts/set-email-address";13import getAccountId from "lib/account/get-account";14import getParams from "lib/api/get-params";1516import { apiRoute, apiRouteOperation } from "lib/api";17import { SuccessStatus } from "lib/api/status";18import {19SetAccountEmailAddressInputSchema,20SetAccountEmailAddressOutputSchema,21} from "lib/api/schema/accounts/set-email-address";2223async function handle(req, res) {24const account_id = await getAccountId(req);25if (account_id == null) {26res.json({ error: "must be signed in" });27return;28}29const { email_address, password } = getParams(req);30try {31await setEmailAddress({ account_id, email_address, password });32res.json(SuccessStatus);33} catch (err) {34if (err.message.includes("duplicate key")) {35err = Error(36`The email address "${email_address}" is already in use by another account.`,37);38}39res.json({ error: err.message });40}41}4243export default apiRoute({44setEmailAddress: apiRouteOperation({45method: "POST",46openApiOperation: {47tags: ["Accounts"],48},49})50.input({51contentType: "application/json",52body: SetAccountEmailAddressInputSchema,53})54.outputs([55{56status: 200,57contentType: "application/json",58body: SetAccountEmailAddressOutputSchema,59},60])61.handler(handle),62});636465