CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/accounts/send-verification-email.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Send verification email
8
*/
9
10
import sendEmailVerification from "@cocalc/server/accounts/send-email-verification";
11
import getAccountId from "lib/account/get-account";
12
import { apiRoute, apiRouteOperation } from "lib/api";
13
import { SuccessStatus } from "lib/api/status";
14
import {
15
SendAccountVerificationEmailInputSchema,
16
SendAccountVerificationEmailOutputSchema,
17
} from "lib/api/schema/accounts/send-verification-email";
18
19
async function handle(req, res) {
20
const account_id = await getAccountId(req);
21
if (account_id == null) {
22
res.json({ error: "must be signed in" });
23
return;
24
}
25
try {
26
const msg = await sendEmailVerification(account_id);
27
28
if (msg) {
29
res.json({ error: msg });
30
} else {
31
res.json(SuccessStatus);
32
}
33
} catch (err) {
34
res.json({ error: err.message });
35
}
36
}
37
38
export default apiRoute({
39
sendVerificationEmail: apiRouteOperation({
40
method: "POST",
41
openApiOperation: {
42
tags: ["Accounts"],
43
},
44
})
45
.input({
46
contentType: "application/json",
47
body: SendAccountVerificationEmailInputSchema,
48
})
49
.outputs([
50
{
51
status: 200,
52
contentType: "application/json",
53
body: SendAccountVerificationEmailOutputSchema,
54
},
55
])
56
.handler(handle),
57
});
58
59