{"record":{"id":"01ec426012c0b073","repo":"beekeeper-studio/beekeeper-studio","slug":"no-pin-found-01ec42","errorCode":null,"errorMessage":"No pin found.","messagePattern":"No pin found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/studio/src/common/appdb/models/UserPin.ts","lineNumber":55,"sourceCode":"    }\n\n    const isOldPinCorrect = await UserPin.verifyPin(oldPin, userPin);\n    if (!isOldPinCorrect) {\n      throw new Error(\"Old pin is incorrect\");\n    }\n\n    if (newPin.length < bksConfig.security.minPinLength) {\n      throw new Error(`Pin must be at least ${bksConfig.security.minPinLength} characters long`);\n    }\n\n    userPin.hash = await bcrypt.hash(newPin, saltRounds);\n\n    return await userPin.save();\n  }\n\n  static async verifyPin(pin: string, userPin?: UserPin): Promise<boolean> {\n    if ((await UserPin.count()) === 0) {\n      throw new Error(\"No pin found.\");\n    }\n    if (!userPin) {\n      userPin = (await UserPin.find())[0];\n    }\n    return await bcrypt.compare(pin, userPin.hash);\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":63,"githubUrl":"https://github.com/beekeeper-studio/beekeeper-studio/blob/4e3e03e3223b2b71a1af8926d455f533b80af837/apps/studio/src/common/appdb/models/UserPin.ts#L37-L63","documentation":"UserPin.verifyPin compares a candidate pin against the stored bcrypt hash. If no UserPin row exists at all (count === 0) it throws \"No pin found.\" instead of returning false, because there is nothing to compare against — verification requires a pin to have been set.","triggerScenarios":"Calling UserPin.verifyPin(pin) (with or without an explicit userPin argument) when UserPin.count() === 0 — e.g. unlock or auth checks running before any pin was created.","commonSituations":"Unlock prompt shown on a fresh install with no pin configured; app databases wiped or migrated without the pin table populated; tests calling verifyPin before seeding a pin.","solutions":["Check UserPin.count() > 0 before calling verifyPin; skip pin verification entirely when none is set.","Create a pin first (UserPin.createPin) if the feature requires one.","Catch the error and treat it as 'pin not configured' to route the user to setup instead of unlock."],"exampleFix":"// before\nconst ok = await UserPin.verifyPin(input);\n// after\nif ((await UserPin.count()) === 0) {\n  return; // no pin configured, nothing to verify\n}\nconst ok = await UserPin.verifyPin(input);","handlingStrategy":"validation","validationCode":"const pinConfigured = (await UserPin.count()) > 0;\nif (!pinConfigured) {\n  return; // nothing to verify; skip unlock or route to setup\n}","typeGuard":null,"tryCatchPattern":"try {\n  const ok = await UserPin.verifyPin(input);\n} catch (e) {\n  if (e.message === 'No pin found.') {\n    // treat as 'pin not configured' — route to setup flow\n  }\n}","preventionTips":["Check UserPin.count() before showing unlock/verification prompts.","Never call verifyPin on profiles where setup has not run.","Seed a pin in tests before any verification assertions."],"tags":["security","pin","missing-record"],"backgroundTag":"pin-not-set","analyzedSha":"4e3e03e3223b2b71a1af8926d455f533b80af837","analyzedAt":"2026-08-31T23:21:23.379Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}