diff --git a/account/src/lib/couch-db.ts b/account/src/lib/couch-db.ts index 7b18f4f..4c53e66 100644 --- a/account/src/lib/couch-db.ts +++ b/account/src/lib/couch-db.ts @@ -125,7 +125,14 @@ export async function createWordlistDatabase(uuid: T.UUID): Promise<{ name: T.Wo export async function deleteWordlistDatabase(uuid: T.UUID): Promise { const name = getWordlistDbName(uuid); - await nano.db.destroy(name); + try { + await nano.db.destroy(name); + } catch (e) { + // allow the error to pass if we're just trying to delete a database that never existed + if (e.message !== "Database does not exist.") { + throw new Error("error deleting database"); + } + } } function generateWordlistDbPassword(): T.UserDbPassword { diff --git a/account/src/routers/api-router.ts b/account/src/routers/api-router.ts index 33dad97..f4a4d9a 100644 --- a/account/src/routers/api-router.ts +++ b/account/src/routers/api-router.ts @@ -135,10 +135,11 @@ apiRouter.put("/user/upgrade", async (req, res, next) => { apiRouter.delete("/user", async (req, res, next) => { try { if (!req.user) throw new Error("user not found"); - const dUser = deleteLingdocsUser(req.user.userId); - const dDb = deleteWordlistDatabase(req.user.userId); - await Promise.all([dUser, dDb]); - sendResponse(res, { ok: true, message: "user delted" }); + await Promise.all([ + deleteWordlistDatabase(req.user.userId), + deleteLingdocsUser(req.user.userId), + ]); + sendResponse(res, { ok: true, message: "user deleted" }); } catch (e) { next(e); } diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index 71de81b..d5a8712 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -128,7 +128,6 @@ const authRouter = (passport: PassportStatic) => { router.post("/register", async (req, res, next) => { try { const { email, password, name } = req.body; - console.log(email, password, name); const existingUser = await getLingdocsUser("email", email); if (existingUser) return res.send("User Already Exists"); const user = await createNewUser({ strategy: "local", email, passwordPlainText: password, name }); diff --git a/website/src/lib/backend-calls.ts b/website/src/lib/backend-calls.ts index ce2ebd7..2b19b46 100644 --- a/website/src/lib/backend-calls.ts +++ b/website/src/lib/backend-calls.ts @@ -16,9 +16,7 @@ async function accountApiFetch(url: string, method: "GET" | "POST" | "PUT" | "DE body: JSON.stringify(body), } : {}, }); - const raw = await response.text(); - console.log("api response:", raw); - return JSON.parse(raw) as AT.APIResponse; + return await response.json() as AT.APIResponse; } export async function publishDictionary(): Promise {