From db3b3ce476c222841019043394aca2afb0c99a18 Mon Sep 17 00:00:00 2001 From: Sokratis Vidros Date: Wed, 9 Feb 2022 15:24:35 +0200 Subject: [PATCH] fix(clerk-js): Prevent post auth redirects in Metamask flow Check if session is created before calling Clerk.setSession and redirecting the user. Especially during sign ups, the session wont be created unless all the sign up requirements (e.g. names and emails) are met. --- packages/clerk-js/src/core/clerk.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index 76f60480dd..dec5ce5fce 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -560,12 +560,14 @@ export default class Clerk implements ClerkInterface { } } - await this.setSession(signInOrSignUp.createdSessionId, () => { - if (redirectUrl) { - return this.navigate(redirectUrl); - } - return Promise.resolve(); - }); + if (signInOrSignUp.createdSessionId) { + await this.setSession(signInOrSignUp.createdSessionId, () => { + if (redirectUrl) { + return this.navigate(redirectUrl); + } + return Promise.resolve(); + }); + } }; updateClient = (newClient: ClientResource): void => {