diff --git a/apps/meteor/client/startup/startup.ts b/apps/meteor/client/startup/startup.ts index 45fa6c12b1bbb..30c4a381e9d85 100644 --- a/apps/meteor/client/startup/startup.ts +++ b/apps/meteor/client/startup/startup.ts @@ -12,8 +12,7 @@ import { watchUserId } from '../meteor/user'; Meteor.startup(() => { let status: UserStatus | undefined = undefined; Tracker.autorun(async () => { - const uid = watchUserId(); - if (!uid) { + if (Meteor.loggingOut()) { removeLocalUserData(); return; } @@ -26,6 +25,12 @@ Meteor.startup(() => { return; } + const uid = watchUserId(); + + if (!uid) { + return; + } + const user = await synchronizeUserData(uid); if (!user) { return; diff --git a/packages/web-ui-registration/src/LoginServicesButton.tsx b/packages/web-ui-registration/src/LoginServicesButton.tsx index 7eb22ad5dbfc6..e5488a18ace07 100644 --- a/packages/web-ui-registration/src/LoginServicesButton.tsx +++ b/packages/web-ui-registration/src/LoginServicesButton.tsx @@ -1,4 +1,5 @@ import { Button } from '@rocket.chat/fuselage'; +import { useLocalStorage } from '@rocket.chat/fuselage-hooks'; import type { Keys as IconName } from '@rocket.chat/icons'; import type { LoginService } from '@rocket.chat/ui-contexts'; import { useLoginWithService } from '@rocket.chat/ui-contexts'; @@ -27,14 +28,21 @@ const LoginServicesButton = ({ const { t } = useTranslation(); const handler = useLoginWithService({ service, buttonLabelText, ...props }); + const [isLegacyOAuthEnabled] = useLocalStorage('useLegacyOAuth', false); + const handleOnClick = useCallback(() => { + if (!isLegacyOAuthEnabled) { + window.location.href = `/oauth/${service}`; + return; + } + handler().catch((e: { error?: LoginErrors; reason?: string }) => { if (!e.error || typeof e.error !== 'string') { return; } setError?.([e.error, e.reason]); }); - }, [handler, setError]); + }, [handler, setError, isLegacyOAuthEnabled, service]); return (