MCPcopy
hub / github.com/LAION-AI/Open-Assistant / handler

Function handler

website/src/pages/api/account/delete.ts:9–53  ·  view source on GitHub ↗
(req: NextApiRequest, res: NextApiResponse)

Source from the content-addressed store, hash-verified

7import { getBackendUserCore } from "src/lib/users";
8
9const handler = async (req: NextApiRequest, res: NextApiResponse) => {
10 const token = await getToken({ req });
11 if (!token) {
12 return res.status(403).end();
13 }
14
15 if (req.method !== "DELETE") {
16 return res.status(400).end();
17 }
18
19 console.log("deleting user", token.sub);
20 try {
21 const backendUserCore = await getBackendUserCore(token.sub);
22 const client = createApiClientFromUser(backendUserCore);
23 await client.delete_account(backendUserCore);
24 console.log(`user ${token.sub} deleted from data backend`);
25 } catch (err) {
26 console.error("could not delete user from data backend", err);
27 return res.status(500).end();
28 }
29
30 try {
31 const client = createInferenceClient(token);
32 await client.delete_account();
33 console.log(`user ${token.sub} deleted from inference`);
34 } catch (err) {
35 if (err instanceof AxiosError && err.response.status === 404) {
36 // user does not exist in the inference backend, they have not send any chats
37 // that is okay, we can continue
38 console.log(`user ${token.sub} does not exist on inference`);
39 } else {
40 console.error("could not delete user from inference backend", err);
41 // we don't return here, the other account is already deleted, we have to power through it
42 }
43 }
44
45 try {
46 await prisma.user.delete({ where: { id: token.sub } });
47 console.log(`user ${token.sub} deleted from webdb`);
48 } catch (err) {
49 console.error("could not delete user from webdb", err);
50 // we don't return here, the other account is already deleted, we have to power through
51 }
52 return res.status(200).end();
53};
54
55export default handler;

Callers 3

withoutRoleFunction · 0.50
withRoleFunction · 0.50
withAnyRoleFunction · 0.50

Calls 7

getBackendUserCoreFunction · 0.90
createApiClientFromUserFunction · 0.90
createInferenceClientFunction · 0.90
endMethod · 0.80
logMethod · 0.80
delete_accountMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected