diff --git a/apps/meteor/app/github-enterprise/client/lib.ts b/apps/meteor/app/github-enterprise/client/hooks/useGitHubEnterpriseAuth.ts similarity index 64% rename from apps/meteor/app/github-enterprise/client/lib.ts rename to apps/meteor/app/github-enterprise/client/hooks/useGitHubEnterpriseAuth.ts index 97b9e686779..f61af7bde79 100644 --- a/apps/meteor/app/github-enterprise/client/lib.ts +++ b/apps/meteor/app/github-enterprise/client/hooks/useGitHubEnterpriseAuth.ts @@ -1,9 +1,8 @@ import type { OauthConfig } from '@rocket.chat/core-typings'; -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; +import { useSetting } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; -import { CustomOAuth } from '../../custom-oauth/client/CustomOAuth'; -import { settings } from '../../settings/client'; +import { CustomOAuth } from '../../../custom-oauth/client/CustomOAuth'; // GitHub Enterprise Server CallBack URL needs to be http(s)://{rocketchat.server}[:port]/_oauth/github_enterprise // In RocketChat -> Administration the URL needs to be http(s)://{github.enterprise.server}/ @@ -20,11 +19,14 @@ const config: OauthConfig = { }; const GitHubEnterprise = new CustomOAuth('github_enterprise', config); -Meteor.startup(() => { - Tracker.autorun(() => { - if (settings.get('API_GitHub_Enterprise_URL')) { - config.serverURL = settings.get('API_GitHub_Enterprise_URL'); + +export const useGitHubEnterpriseAuth = () => { + const githubApiUrl = useSetting('API_GitHub_Enterprise_URL') as string; + + useEffect(() => { + if (githubApiUrl) { + config.serverURL = githubApiUrl; GitHubEnterprise.configure(config); } - }); -}); + }, [githubApiUrl]); +}; diff --git a/apps/meteor/app/github-enterprise/client/index.ts b/apps/meteor/app/github-enterprise/client/index.ts deleted file mode 100644 index cf327e4971b..00000000000 --- a/apps/meteor/app/github-enterprise/client/index.ts +++ /dev/null @@ -1 +0,0 @@ -import './lib'; diff --git a/apps/meteor/client/importPackages.ts b/apps/meteor/client/importPackages.ts index 59e7ec3d7c8..1012411574f 100644 --- a/apps/meteor/client/importPackages.ts +++ b/apps/meteor/client/importPackages.ts @@ -10,7 +10,6 @@ import '../app/emoji/client'; import '../app/emoji-emojione/client'; import '../app/emoji-custom/client'; import '../app/file-upload/client'; -import '../app/github-enterprise/client'; import '../app/gitlab/client'; import '../app/iframe-login/client'; import '../app/license/client'; diff --git a/apps/meteor/client/views/root/AppLayout.tsx b/apps/meteor/client/views/root/AppLayout.tsx index dbe0fa49a56..da0eada88e2 100644 --- a/apps/meteor/client/views/root/AppLayout.tsx +++ b/apps/meteor/client/views/root/AppLayout.tsx @@ -7,6 +7,7 @@ import { useGoogleTagManager } from './hooks/useGoogleTagManager'; import { useMessageLinkClicks } from './hooks/useMessageLinkClicks'; import { useSettingsOnLoadSiteUrl } from './hooks/useSettingsOnLoadSiteUrl'; import { useAnalytics } from '../../../app/analytics/client/loadScript'; +import { useGitHubEnterpriseAuth } from '../../../app/github-enterprise/client/hooks/useGitHubEnterpriseAuth'; import { useGitLabAuth } from '../../../app/gitlab/client/hooks/useGitLabAuth'; import { useLivechatEnterprise } from '../../../app/livechat-enterprise/hooks/useLivechatEnterprise'; import { useNextcloud } from '../../../app/nextcloud/client/useNextcloud'; @@ -36,8 +37,8 @@ const AppLayout = () => { useSettingsOnLoadSiteUrl(); useLivechatEnterprise(); useNextcloud(); - useGitLabAuth(); + useGitHubEnterpriseAuth(); const layout = useSyncExternalStore(appLayout.subscribe, appLayout.getSnapshot);