Skip to content

Commit 9cd68a6

Browse files
committed
fix(js): preserve SignUpFuture reference across SSO-to-sign-up transition
When an SSO sign-in transitions to a sign-up flow (e.g. account does not exist, legal acceptance required), Client.fromJSON created a brand-new SignUp instance because the existing one had no id and the incoming data did. The old SignUpFuture held by useSignUp() hooks pointed at the stale id-less instance, so subsequent update() calls sent PATCH to /client/sign_ups instead of /client/sign_ups/{id} and received a 405. Fix: update the existing SignUp in-place (via __internal_updateFromJSON) when it has no id yet, which preserves the SignUpFuture reference and ensures hooks see the correct id after the transition. Fixes #8338
1 parent 04bbfe9 commit 9cd68a6

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/clerk-js": patch
3+
---
4+
5+
Fix `signUp.update()` sending a PATCH request to `/client/sign_ups` instead of `/client/sign_ups/{id}` after an SSO sign-in transitions to a sign-up flow (e.g. when legal acceptance is required). The `SignUpFuture` reference held by hooks is now preserved across the transition and reflects the correct sign-up id.

packages/clerk-js/src/core/resources/Client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ export class Client extends BaseResource implements ClientResource {
143143
this.id = data.id;
144144
this.sessions = (data.sessions || []).map(s => new Session(s));
145145

146-
if (data.sign_up && this.signUp instanceof SignUp && this.signUp.id === data.sign_up.id) {
146+
if (data.sign_up && this.signUp instanceof SignUp && (this.signUp.id === data.sign_up.id || !this.signUp.id)) {
147+
// Update in-place when ids match OR when the existing signUp has no id yet
148+
// (e.g. an SSO sign-in that transitions to a sign-up flow). Reusing the same
149+
// SignUp instance preserves any SignUpFuture references held by hooks so they
150+
// remain valid and reflect the correct id after the transition.
147151
this.signUp.__internal_updateFromJSON(data.sign_up);
148152
} else {
149153
this.signUp = new SignUp(data.sign_up);

0 commit comments

Comments
 (0)