summaryrefslogtreecommitdiff
path: root/api/db/_deleteUserAuthenticators.ts
blob: 32f4ea595a1f26fedd5dbfcaa7c4a83ebb750524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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}`);
  }
}