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/delete.ts
Views: 687
1
/*
2
Delete the account that the user is currently signed in using.
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import deleteAccount from "@cocalc/server/accounts/delete";
7
import isPost from "lib/api/is-post";
8
import { apiRoute, apiRouteOperation } from "lib/api";
9
import { SuccessStatus } from "lib/api/status";
10
import { DeleteAccountOutputSchema } from "lib/api/schema/accounts/delete";
11
12
async function handle(req, res) {
13
try {
14
if (isPost(req, res)) {
15
const account_id = await getAccountId(req);
16
if (!account_id) {
17
throw Error("must be signed in");
18
}
19
await deleteAccount(account_id);
20
res.json(SuccessStatus);
21
} else {
22
throw Error("must be a POST request");
23
}
24
} catch (err) {
25
res.json({ error: err.message });
26
}
27
}
28
29
export default apiRoute({
30
delete: apiRouteOperation({
31
method: "POST",
32
openApiOperation: {
33
tags: ["Accounts"],
34
},
35
})
36
.outputs([
37
{
38
status: 200,
39
contentType: "application/json",
40
body: DeleteAccountOutputSchema,
41
},
42
])
43
.handler(handle),
44
});
45
46