Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/bump-patch-1758105326594.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Bump @rocket.chat/meteor version.
5 changes: 5 additions & 0 deletions .changeset/green-ants-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
Comment thread
ggazzo marked this conversation as resolved.
Outdated
---

Fixes login using iframe authentication.
20 changes: 14 additions & 6 deletions apps/meteor/client/hooks/iframe/useIframe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLoginWithIframe, useLoginWithToken, useSetting } from '@rocket.chat/ui-contexts';
import { useCallback, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';

export const useIframe = () => {
const [iframeLoginUrl, setIframeLoginUrl] = useState<string | undefined>(undefined);
Expand All @@ -12,6 +12,8 @@ export const useIframe = () => {
const iframeLogin = useLoginWithIframe();
const tokenLogin = useLoginWithToken();

const enabled = Boolean(iframeEnabled && accountIframeUrl && apiUrl && apiMethod);

const loginWithToken = useCallback(
(tokenData: string | { loginToken: string } | { token: string }, callback?: (error: Error | null | undefined) => void) => {
if (typeof tokenData === 'string') {
Expand All @@ -31,6 +33,10 @@ export const useIframe = () => {

const tryLogin = useCallback(
async (callback?: (error: Error | null | undefined, result: unknown) => void) => {
if (!enabled) {
return;
}

let url = accountIframeUrl;
let separator = '?';
if (url.indexOf('?') > -1) {
Expand All @@ -43,9 +49,7 @@ export const useIframe = () => {

const result = await fetch(apiUrl, {
method: apiMethod,
headers: {
'Content-Type': 'application/json',
},
headers: undefined,
credentials: 'include',
});

Expand All @@ -64,11 +68,15 @@ export const useIframe = () => {
callback?.(error, await result.json());
});
},
[apiMethod, apiUrl, accountIframeUrl, loginWithToken],
[apiMethod, apiUrl, accountIframeUrl, loginWithToken, enabled],
);

useEffect(() => {
tryLogin();
}, [tryLogin]);

return {
enabled: Boolean(iframeEnabled && accountIframeUrl && apiUrl && apiMethod),
enabled,
tryLogin,
loginWithToken,
iframeLoginUrl,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9387,7 +9387,7 @@ __metadata:
peerDependencies:
"@rocket.chat/layout": "*"
"@rocket.chat/tools": 0.2.3
"@rocket.chat/ui-contexts": 22.0.0-rc.6
"@rocket.chat/ui-contexts": 22.0.0
"@tanstack/react-query": "*"
react: "*"
react-hook-form: "*"
Expand Down
Loading