Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-cars-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue with iframe authentication where login should always fallback to iframe authentication in case of any erorrs.
39 changes: 22 additions & 17 deletions apps/meteor/client/hooks/iframe/useIframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,31 @@ export const useIframe = () => {
url += `${separator}client=electron`;
}

const result = await fetch(apiUrl, {
method: apiMethod,
headers: undefined,
credentials: 'include',
});
try {
const result = await fetch(apiUrl, {
method: apiMethod,
headers: undefined,
credentials: 'include',
});

if (!result.ok || result.status !== 200) {
setIframeLoginUrl(url);
callback?.(new Error(), null);
return;
}

loginWithToken(await result.json(), async (error: Meteor.Error | Meteor.TypedError | Error | null | undefined) => {
if (error) {
if (!result.ok || result.status !== 200) {
setIframeLoginUrl(url);
} else {
setIframeLoginUrl(undefined);
callback?.(new Error(), null);
return;
}
callback?.(error, await result.json());
});

loginWithToken(await result.json(), async (error: Meteor.Error | Meteor.TypedError | Error | null | undefined) => {
if (error) {
setIframeLoginUrl(url);
} else {
setIframeLoginUrl(undefined);
}
callback?.(error, await result.json());
});
} catch (error) {
setIframeLoginUrl(url);
callback?.(error instanceof Error ? error : undefined, null);
}
},
[apiMethod, apiUrl, accountIframeUrl, loginWithToken, enabled],
);
Expand Down
Loading