Skip to content

Commit e7aacb2

Browse files
authored
fix: Restore iframe authentication behavior (RocketChat#36866)
1 parent 2b9cc5d commit e7aacb2

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

.changeset/curvy-cars-attend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes an issue with iframe authentication where login should always fallback to iframe authentication in case of any erorrs.

apps/meteor/client/hooks/iframe/useIframe.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,31 @@ export const useIframe = () => {
4747
url += `${separator}client=electron`;
4848
}
4949

50-
const result = await fetch(apiUrl, {
51-
method: apiMethod,
52-
headers: undefined,
53-
credentials: 'include',
54-
});
50+
try {
51+
const result = await fetch(apiUrl, {
52+
method: apiMethod,
53+
headers: undefined,
54+
credentials: 'include',
55+
});
5556

56-
if (!result.ok || result.status !== 200) {
57-
setIframeLoginUrl(url);
58-
callback?.(new Error(), null);
59-
return;
60-
}
61-
62-
loginWithToken(await result.json(), async (error: Meteor.Error | Meteor.TypedError | Error | null | undefined) => {
63-
if (error) {
57+
if (!result.ok || result.status !== 200) {
6458
setIframeLoginUrl(url);
65-
} else {
66-
setIframeLoginUrl(undefined);
59+
callback?.(new Error(), null);
60+
return;
6761
}
68-
callback?.(error, await result.json());
69-
});
62+
63+
loginWithToken(await result.json(), async (error: Meteor.Error | Meteor.TypedError | Error | null | undefined) => {
64+
if (error) {
65+
setIframeLoginUrl(url);
66+
} else {
67+
setIframeLoginUrl(undefined);
68+
}
69+
callback?.(error, await result.json());
70+
});
71+
} catch (error) {
72+
setIframeLoginUrl(url);
73+
callback?.(error instanceof Error ? error : undefined, null);
74+
}
7075
},
7176
[apiMethod, apiUrl, accountIframeUrl, loginWithToken, enabled],
7277
);

0 commit comments

Comments
 (0)