mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
added migration for simplewebauthn
This commit is contained in:
34
server/setup/scriptsSqlite/1.10.4.ts
Normal file
34
server/setup/scriptsSqlite/1.10.4.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { APP_PATH } from "@server/lib/consts";
|
||||
import Database from "better-sqlite3";
|
||||
import path from "path";
|
||||
import { isoBase64URL } from "@simplewebauthn/server/helpers";
|
||||
|
||||
const version = "1.10.4";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
db.transaction(() => {
|
||||
|
||||
const webauthnCredentials = db.prepare(`SELECT credentialId, publicKey FROM 'webauthnCredentials'`).all() as {
|
||||
credentialId: string; publicKey: string
|
||||
}[];
|
||||
|
||||
for (const webauthnCredential of webauthnCredentials) {
|
||||
const credentialId = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.credentialId, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'credentialId' = ?`
|
||||
).run(credentialId);
|
||||
|
||||
const publicKey = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.publicKey, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'publicKey' = ?`
|
||||
).run(publicKey);
|
||||
}
|
||||
})();
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
}
|
||||
Reference in New Issue
Block a user