Skip to content

Commit dea9fbe

Browse files
waleedlatif1claude
andcommitted
fix: handle legacy OTP format in decodeOTPValue for deploy-time compat
Add guard for OTP values without colon separator (pre-deploy format) to avoid misparse that would lock out users with in-flight OTPs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 35bc843 commit dea9fbe

File tree

1 file changed

+3
-4
lines changed
  • apps/sim/app/api/chat/[identifier]/otp

1 file changed

+3
-4
lines changed

apps/sim/app/api/chat/[identifier]/otp/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ function encodeOTPValue(otp: string, attempts: number): string {
3434

3535
function decodeOTPValue(value: string): { otp: string; attempts: number } {
3636
const lastColon = value.lastIndexOf(':')
37-
return {
38-
otp: value.slice(0, lastColon),
39-
attempts: Number.parseInt(value.slice(lastColon + 1), 10),
40-
}
37+
if (lastColon === -1) return { otp: value, attempts: 0 }
38+
const attempts = Number.parseInt(value.slice(lastColon + 1), 10)
39+
return { otp: value.slice(0, lastColon), attempts: Number.isNaN(attempts) ? 0 : attempts }
4140
}
4241

4342
/**

0 commit comments

Comments
 (0)