feat: prevent basic subscribers from accessing premium news details

This commit is contained in:
fredy.siswanto 2025-03-15 01:08:38 +07:00
parent 3ddc657cfb
commit cbfb8e72cc

View File

@ -18,6 +18,12 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => {
const { data: userData } = await getUser({ accessToken }) const { data: userData } = await getUser({ accessToken })
const { slug } = params const { slug } = params
const { data: newsDetailData } = await getNewsBySlug({ slug, accessToken }) const { data: newsDetailData } = await getNewsBySlug({ slug, accessToken })
if (
userData.subscribe.subscribe_plan.code === 'basic' &&
newsDetailData.is_premium
) {
return redirect('/')
}
const { data: categoriesData } = await getCategories() const { data: categoriesData } = await getCategories()
const beritaCode = 'berita' const beritaCode = 'berita'
const beritaCategory = categoriesData.find( const beritaCategory = categoriesData.find(
@ -26,13 +32,6 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => {
let { data: beritaNews } = await getNews({ categories: [beritaCode] }) let { data: beritaNews } = await getNews({ categories: [beritaCode] })
beritaNews = beritaNews.filter((news) => new Date(news.live_at) <= new Date()) beritaNews = beritaNews.filter((news) => new Date(news.live_at) <= new Date())
if (
userData.subscribe.subscribe_plan.code === 'basic' &&
newsDetailData.is_premium
) {
return redirect('/')
}
return { return {
newsDetailData, newsDetailData,
beritaCategory, beritaCategory,