Files
indee-demo/src/composables/useAccess.ts
Dorian c970f5b29f Enhance deployment script and update package dependencies
- Added detailed labels to the deployment script for IndeedHub, including title, version, description, license, icon, and repository URL.
- Updated package dependencies in package.json and package-lock.json, including upgrading 'nostr-tools' to version 2.23.0 and adding 'axios' and '@tanstack/vue-query'.
- Improved README with a modern description of the platform and updated project structure details.

This commit enhances the clarity of the deployment process and ensures the project is using the latest dependencies for better performance and features.
2026-02-12 10:30:47 +00:00

91 lines
2.2 KiB
TypeScript

import { computed } from 'vue'
import { libraryService } from '../services/library.service'
import { subscriptionService } from '../services/subscription.service'
import { useAuthStore } from '../stores/auth'
/**
* Access Control Composable
* Check user access to content (subscription or rental)
*/
export function useAccess() {
const authStore = useAuthStore()
/**
* Check if user has access to specific content
*/
async function checkContentAccess(contentId: string): Promise<{
hasAccess: boolean
method?: 'subscription' | 'rental'
expiresAt?: string
}> {
if (!authStore.isAuthenticated) {
return { hasAccess: false }
}
// Check subscription first (instant check)
if (authStore.hasActiveSubscription()) {
return { hasAccess: true, method: 'subscription' }
}
// Check if we're in development mode
const useMockData = import.meta.env.VITE_USE_MOCK_DATA === 'true' || import.meta.env.DEV
if (useMockData) {
// In dev mode without subscription, no access (prompt rental)
return { hasAccess: false }
}
// Real API call to check rental
try {
return await libraryService.checkContentAccess(contentId)
} catch (error) {
console.error('Failed to check access:', error)
return { hasAccess: false }
}
}
/**
* Check if user has active subscription
*/
const hasActiveSubscription = computed(() => {
return authStore.hasActiveSubscription()
})
/**
* Get user's subscription tier
*/
async function getSubscriptionTier() {
if (!authStore.isAuthenticated) return null
try {
const subscription = await subscriptionService.getActiveSubscription()
return subscription?.tier || null
} catch {
return null
}
}
/**
* Check if content requires subscription
*/
function requiresSubscription(_content: any): boolean {
// All content requires subscription or rental unless explicitly free
return true
}
/**
* Check if content can be rented
*/
function canRent(_content: any): boolean {
return !!_content.rentalPrice && _content.rentalPrice > 0
}
return {
checkContentAccess,
hasActiveSubscription,
getSubscriptionTier,
requiresSubscription,
canRent,
}
}