Skip to content

Commit d89c0cf

Browse files
authored
Single source of truth for platform auth type. (#5320)
1 parent fa39cc7 commit d89c0cf

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

app/components-react/pages/PlatformMerge.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { useState } from 'react';
22
import { EAuthProcessState } from 'services/user';
33
import { $t } from 'services/i18n';
4-
import { EPlatformCallResult, getPlatformService, TPlatform } from '../../services/platforms';
4+
import {
5+
EPlatformCallResult,
6+
externalAuthPlatforms,
7+
getPlatformService,
8+
TPlatform,
9+
} from '../../services/platforms';
510
import { Services } from 'components-react/service-provider';
611
import { useVuex } from 'components-react/hooks';
712
import { alertAsync } from 'components-react/modals';
@@ -38,9 +43,7 @@ export default function PlatformMerge(p: IPlatformMergeProps) {
3843

3944
async function mergePlatform() {
4045
if (!platform) return;
41-
const mode = ['youtube', 'twitch', 'twitter', 'tiktok', 'kick'].includes(platform)
42-
? 'external'
43-
: 'internal';
46+
const mode = externalAuthPlatforms.includes(platform) ? 'external' : 'internal';
4447
await UserService.actions.return
4548
.startAuth(platform, mode, true)
4649
.then(res => {

app/components-react/pages/onboarding/Connect.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { $t } from 'services/i18n';
55
import { Services } from 'components-react/service-provider';
66
import { injectState, useModule, mutation } from 'slap';
77
import { ExtraPlatformConnect } from './ExtraPlatformConnect';
8-
import { EPlatform, EPlatformCallResult, TPlatform, platformLabels } from 'services/platforms';
8+
import {
9+
EPlatform,
10+
EPlatformCallResult,
11+
TPlatform,
12+
externalAuthPlatforms,
13+
platformLabels,
14+
} from 'services/platforms';
915
import * as remote from '@electron/remote';
1016
import { OnboardingModule } from './Onboarding';
1117
import { EAuthProcessState } from 'services/user';
@@ -265,9 +271,7 @@ export class LoginModule {
265271

266272
const result = await this.UserService.startAuth(
267273
platform,
268-
['youtube', 'twitch', 'twitter', 'tiktok', 'kick'].includes(platform)
269-
? 'external'
270-
: 'internal',
274+
externalAuthPlatforms.includes(platform) ? 'external' : 'internal',
271275
merge,
272276
);
273277

app/components-react/windows/settings/Stream.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import React, { useMemo, useState } from 'react';
22
import { $t } from '../../../services/i18n';
33
import { ICustomStreamDestination } from '../../../services/settings/streaming';
44
import { EStreamingState } from '../../../services/streaming';
5-
import { EPlatformCallResult, getPlatformService, TPlatform } from '../../../services/platforms';
5+
import {
6+
EPlatformCallResult,
7+
externalAuthPlatforms,
8+
getPlatformService,
9+
TPlatform,
10+
} from '../../../services/platforms';
611
import cloneDeep from 'lodash/cloneDeep';
712
import namingHelpers from '../../../util/NamingHelpers';
813
import { Services } from '../../service-provider';
@@ -217,9 +222,7 @@ class StreamSettingsModule {
217222
}
218223

219224
async platformMergeInline(platform: TPlatform) {
220-
const mode = ['youtube', 'twitch', 'twitter', 'tiktok', 'kick'].includes(platform)
221-
? 'external'
222-
: 'internal';
225+
const mode = externalAuthPlatforms.includes(platform) ? 'external' : 'internal';
223226

224227
await Services.UserService.actions.return.startAuth(platform, mode, true).then(res => {
225228
Services.WindowsService.actions.setWindowOnTop('child');

app/services/platforms/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,5 @@ export function getPlatformService(platform: TPlatform): IPlatformService {
302302
export interface IPlatformRequest extends RequestInit {
303303
url: string;
304304
}
305+
306+
export const externalAuthPlatforms = ['youtube', 'twitch', 'twitter', 'tiktok', 'kick'];

0 commit comments

Comments
 (0)