Skip to content

Commit b6b8a12

Browse files
authored
fix(clerk-js): Prevent infinite loop when client is blocked (#5083)
1 parent 0fa449c commit b6b8a12

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.changeset/tasty-socks-hide.md

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+
Prevent infinite loop when the client is blocked

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,15 +1493,24 @@ export class Clerk implements ClerkInterface {
14931493
if (!this.client || !this.session) {
14941494
return;
14951495
}
1496-
const newClient = await Client.getOrCreateInstance().fetch();
1497-
this.updateClient(newClient);
1498-
if (this.session) {
1499-
return;
1500-
}
1501-
if (opts.broadcast) {
1502-
this.#broadcastSignOutEvent();
1496+
try {
1497+
const newClient = await Client.getOrCreateInstance().fetch();
1498+
this.updateClient(newClient);
1499+
if (this.session) {
1500+
return;
1501+
}
1502+
if (opts.broadcast) {
1503+
this.#broadcastSignOutEvent();
1504+
}
1505+
return this.setActive({ session: null });
1506+
} catch (err) {
1507+
// Handle the 403 Forbidden
1508+
if (err.status === 403) {
1509+
return this.setActive({ session: null });
1510+
} else {
1511+
throw err;
1512+
}
15031513
}
1504-
return this.setActive({ session: null });
15051514
};
15061515

15071516
public authenticateWithGoogleOneTap = async (

0 commit comments

Comments
 (0)