diff --git a/account/src/lib/couch-db.ts b/account/src/lib/couch-db.ts index 02bfb79..7b18f4f 100644 --- a/account/src/lib/couch-db.ts +++ b/account/src/lib/couch-db.ts @@ -123,6 +123,11 @@ export async function createWordlistDatabase(uuid: T.UUID): Promise<{ name: T.Wo return { password, name }; } +export async function deleteWordlistDatabase(uuid: T.UUID): Promise { + const name = getWordlistDbName(uuid); + await nano.db.destroy(name); +} + function generateWordlistDbPassword(): T.UserDbPassword { function makeChunk(): string { return Math.random().toString(36).slice(2) diff --git a/account/src/routers/api-router.ts b/account/src/routers/api-router.ts index 8cfa0f6..b3257b2 100644 --- a/account/src/routers/api-router.ts +++ b/account/src/routers/api-router.ts @@ -106,7 +106,8 @@ apiRouter.put("/user/upgrade", async (req, res, next) => { } const { userId } = req.user; const user = await getLingdocsUser("userId", userId); - if (user) { + if (!user) throw new Error("user lost"); + if (user.level !== "basic") { const alreadyUpgraded: T.UpgradeUserResponse = { ok: true, message: "user already upgraded", diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index d1ce8a4..71de81b 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -128,8 +128,9 @@ 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("Tser Already Exists"); + if (existingUser) return res.send("User Already Exists"); const user = await createNewUser({ strategy: "local", email, passwordPlainText: password, name }); req.logIn(user, (err) => { if (err) return next(err);