Skip to content

Commit

Permalink
fix: protect media play use APP_OAUTH_UNLOCK_ONLY_PREMIUM in condit…
Browse files Browse the repository at this point in the history
…ions

Previously despite setting `APP_OAUTH_UNLOCK_ONLY_PREMIUM=true`
videos for logged in user could not be played.
  • Loading branch information
pawelkmpt committed Oct 16, 2024
1 parent f98d51a commit f3d3758
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/hooks-react/src/useContentProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AccountController from '@jwp/ott-common/src/controllers/AccountController
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { isTruthyCustomParamValue } from '@jwp/ott-common/src/utils/common';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import env from '@jwp/ott-common/src/env';

import { generateJwtSignedContentToken, useOAuth } from './useOAuth';

Expand Down Expand Up @@ -57,11 +58,15 @@ const useContentProtection = <T>(
// if self-signed is enabled in jwp dashboard
// and
// isOAuthMode is enabled and user is logged in and in premium mode
if (!!id && signingEnabled && isOAuthMode && !!user && !!user?.isPremium) {
if (!!id && signingEnabled && isOAuthMode && !!user && (env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !!user?.isPremium : true)) {
return generateJwtSignedContentToken(id, `Bearer ${bearerToken}`);
}
},
{ enabled: signingEnabled && enabled && !!id && (isOAuthMode ? !!user?.isPremium : false), keepPreviousData: false, staleTime: 15 * 60 * 1000 },
{
enabled: signingEnabled && enabled && !!id && (isOAuthMode ? (env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !!user?.isPremium : true) : false),
keepPreviousData: false,
staleTime: 15 * 60 * 1000,
},
);

const queryResult = useQuery<T | undefined>([type, id, params, token], async () => callback(token, drmPolicyId), {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks-react/src/useProtectedMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
import ApiService from '@jwp/ott-common/src/services/ApiService';
import { getModule } from '@jwp/ott-common/src/modules/container';
import env from '@jwp/ott-common/src/env';

import useContentProtection from './useContentProtection';

Expand All @@ -15,7 +16,7 @@ export default function useProtectedMedia(item: PlaylistItem) {
useEffect(() => {
const m3u8 = contentProtectionQuery.data?.sources.find((source) => source.file.indexOf('.m3u8') !== -1);
if (!m3u8) {
setIsUserBlocked(!contentProtectionQuery?.user?.isPremium);
setIsUserBlocked(env.APP_OAUTH_UNLOCK_ONLY_PREMIUM ? !contentProtectionQuery?.user?.isPremium : false);
return;
}
fetch(m3u8.file, { method: 'HEAD' }).then((response) => {
Expand Down

0 comments on commit f3d3758

Please sign in to comment.