1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import type Authenticator from '../types/Authenticator';
import { sql } from '@vercel/postgres';
import { AUTHENTICATORS } from './_tables';
export default async function addAuthenticator(authenticator: Authenticator) {
try {
await sql.query(`
INSERT INTO ${AUTHENTICATORS.name} (
${AUTHENTICATORS.fields.id},
${AUTHENTICATORS.fields.backedUp},
${AUTHENTICATORS.fields.counter},
${AUTHENTICATORS.fields.deviceType},
${AUTHENTICATORS.fields.publicKey}
${AUTHENTICATORS.fields.transports},
${AUTHENTICATORS.fields.type},
${AUTHENTICATORS.fields.userId}
) VALUES (
${authenticator.id},
${authenticator.backedUp},
${authenticator.counter},
${authenticator.deviceType},
${authenticator.publicKey}
{ ${authenticator.transports.join(', ')} },
${authenticator.type},
${authenticator.userId}
);
`);
} catch (err) {
throw new Error(`Failed to insert authenticator into database: ${JSON.stringify(authenticator)}.`, err);
}
}
|