Skip to content

Commit 9579935

Browse files
committed
fix(runtime): SSO handoff value must be unique (embed token)
The cloud-minted SSO handoff (`sso_as_owner` / 'Open' button) writes a `sys_verification` row whose unique token lives in `identifier` (`sso-handoff:<token>`) while `value` held a static JSON payload {email,name,by,envId}. But `sys_verification.value` carries a UNIQUE index (it is the OTP/token column for email-verification flows), so opening the SAME environment twice as the same owner produced identical value JSON and the second issuance failed with: UNIQUE constraint failed: sys_verification.value i.e. an operator opening their env a second time got a 500. Embed the unique handoff token (`t`) in the value payload so each issuance is distinct. The sso-exchange consumer only reads email/name, so the extra field is inert.
1 parent 60af8ac commit 9579935

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/runtime/src/cloud/auth-proxy-plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,14 @@ export class AuthProxyPlugin implements Plugin {
257257
const expiresAt = new Date(Date.now() + ttlSec * 1000);
258258
await internal.createVerificationValue({
259259
identifier: `sso-handoff:${handoff}`,
260-
value: JSON.stringify({ email, name, by, envId: envIdInBody ?? environmentId }),
260+
// `sys_verification.value` carries a UNIQUE index (it is the
261+
// OTP/token column for email-verification flows). The handoff
262+
// puts its unique token in `identifier`, so the value payload
263+
// must ALSO embed the token (`t`) — otherwise two handoffs for
264+
// the same owner+env produce identical value JSON and the second
265+
// one fails with `UNIQUE constraint failed: sys_verification.value`
266+
// (i.e. opening the same environment twice 500s).
267+
value: JSON.stringify({ email, name, by, envId: envIdInBody ?? environmentId, t: handoff }),
261268
expiresAt,
262269
});
263270
return c.json({

0 commit comments

Comments
 (0)