From cabab42ec1f4652b36de62315530d501e0b8ea0f Mon Sep 17 00:00:00 2001 From: Juan P Lopez Date: Sat, 23 Nov 2024 19:26:39 -0500 Subject: [PATCH] chore(core): add reset totp debug script --- core/api/src/debug/reset-totp.ts | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core/api/src/debug/reset-totp.ts diff --git a/core/api/src/debug/reset-totp.ts b/core/api/src/debug/reset-totp.ts new file mode 100644 index 0000000000..55adda8c55 --- /dev/null +++ b/core/api/src/debug/reset-totp.ts @@ -0,0 +1,35 @@ +/** + * how to run: + * + * pnpm tsx src/debug/reset-user-totp.ts + * + * : ID of the user whose TOTP needs to be reset + */ + +import { Authentication } from "@/app" + +import { setupMongoConnection } from "@/services/mongodb" + +const main = async () => { + const args = process.argv.slice(-1) + const userId = args[0] as UserId + + if (!userId) { + console.error("Error: User ID is required") + return + } + + const result = await Authentication.removeTotp({ userId }) + if (result instanceof Error) { + console.error("Error:", result) + return + } + console.log(`Successfully reset TOTP for user ${userId}:`, result) +} + +setupMongoConnection() + .then(async (mongoose) => { + await main() + if (mongoose) await mongoose.connection.close() + }) + .catch((err) => console.log(err))