Skip to content

Commit 972f1f6

Browse files
authored
Fix/reset pin logic (#1005)
* check pin validity * Ensure new pin is different from existing
1 parent 96ce887 commit 972f1f6

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

  • infrastructure/eid-wallet/src/routes/(app)/settings/pin

infrastructure/eid-wallet/src/routes/(app)/settings/pin/+page.svelte

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,34 @@ const stepTitle = $derived(
3232
: "Confirm your new PIN",
3333
);
3434
35-
function advance() {
36-
if (!canSubmit) return;
35+
async function advance() {
36+
if (!canSubmit || submitting) return;
3737
error = null;
3838
if (step === "current") {
39-
step = "new";
39+
if (!globalState) return;
40+
submitting = true;
41+
try {
42+
const ok =
43+
await globalState.securityController.verifyPin(currentPin);
44+
if (!ok) {
45+
error = "That's not your current PIN. Try again.";
46+
currentPin = "";
47+
return;
48+
}
49+
step = "new";
50+
} catch (err) {
51+
console.error("Failed to verify current PIN:", err);
52+
error = "Couldn't verify your current PIN. Try again.";
53+
currentPin = "";
54+
} finally {
55+
submitting = false;
56+
}
4057
} else if (step === "new") {
58+
if (newPin === currentPin) {
59+
error = "Your new PIN must be different from your current PIN.";
60+
newPin = "";
61+
return;
62+
}
4163
step = "repeat";
4264
} else {
4365
void submit();
@@ -148,7 +170,7 @@ onMount(() => {
148170
class="w-full uppercase tracking-wide"
149171
disabled={!canSubmit || submitting}
150172
callback={advance}
151-
blockingClick={step === "repeat"}
173+
blockingClick={step !== "new"}
152174
>
153175
{step === "repeat" ? "Change PIN" : "Next"}
154176
</ButtonAction>

0 commit comments

Comments
 (0)