From 19b4835bea200099bae15bc02edd5e4cafa2c46c Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Mon, 22 Jan 2024 14:59:51 +0000 Subject: verifyRegistrationResponse is single-responsibility! --- api/db/_deleteUserAuthenticators.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 api/db/_deleteUserAuthenticators.ts (limited to 'api/db/_deleteUserAuthenticators.ts') diff --git a/api/db/_deleteUserAuthenticators.ts b/api/db/_deleteUserAuthenticators.ts new file mode 100644 index 0000000..32f4ea5 --- /dev/null +++ b/api/db/_deleteUserAuthenticators.ts @@ -0,0 +1,16 @@ +import { sql } from '@vercel/postgres'; +import { AUTHENTICATORS } from './_tables'; +import User from '../types/User'; + +export default async function deleteUserAuthenticators(userId: User['id']) { + const query = ` + DELETE FROM ${AUTHENTICATORS.name} + WHERE ${AUTHENTICATORS.fields.id} = '${id}'; + `; + + try { + await sql.query(query); + } catch (err) { + throw new Error(`Failed to delete authenticators for user with ID ${userId} from database. Query was ${query.replace(/\s+/g, ' ')}. ${err}`); + } +} -- cgit v1.2.3