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.
This commit is contained in:
106
src/router/guards.ts
Normal file
106
src/router/guards.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import type { Router, RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
|
||||
/**
|
||||
* Authentication guard
|
||||
* Redirects to login if not authenticated
|
||||
*/
|
||||
export async function authGuard(
|
||||
to: RouteLocationNormalized,
|
||||
_from: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
) {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Initialize auth if not already done
|
||||
if (!authStore.isAuthenticated && !authStore.isLoading) {
|
||||
await authStore.initialize()
|
||||
}
|
||||
|
||||
if (authStore.isAuthenticated) {
|
||||
next()
|
||||
} else {
|
||||
// Store intended destination for redirect after login
|
||||
sessionStorage.setItem('redirect_after_login', to.fullPath)
|
||||
next('/login')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest guard
|
||||
* Redirects to home if already authenticated (for login/register pages)
|
||||
*/
|
||||
export function guestGuard(
|
||||
_to: RouteLocationNormalized,
|
||||
_from: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
) {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (authStore.isAuthenticated) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscription guard
|
||||
* Checks if user has active subscription
|
||||
*/
|
||||
export function subscriptionGuard(
|
||||
to: RouteLocationNormalized,
|
||||
_from: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
) {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (!authStore.isAuthenticated) {
|
||||
sessionStorage.setItem('redirect_after_login', to.fullPath)
|
||||
next('/login')
|
||||
} else if (authStore.hasActiveSubscription()) {
|
||||
next()
|
||||
} else {
|
||||
// Redirect to subscription page
|
||||
next('/subscription')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filmmaker guard
|
||||
* Restricts access to filmmaker-only routes
|
||||
*/
|
||||
export function filmmakerGuard(
|
||||
to: RouteLocationNormalized,
|
||||
_from: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
) {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (!authStore.isAuthenticated) {
|
||||
sessionStorage.setItem('redirect_after_login', to.fullPath)
|
||||
next('/login')
|
||||
} else if (authStore.isFilmmaker()) {
|
||||
next()
|
||||
} else {
|
||||
// Redirect to home with error message
|
||||
next('/')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup router guards
|
||||
*/
|
||||
export function setupGuards(router: Router) {
|
||||
// Global before guard for auth initialization
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Initialize auth on first navigation
|
||||
if (!authStore.isAuthenticated && !authStore.isLoading && to.meta.requiresAuth) {
|
||||
await authStore.initialize()
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { setupGuards, authGuard } from './guards'
|
||||
import Browse from '../views/Browse.vue'
|
||||
|
||||
const router = createRouter({
|
||||
@@ -7,9 +8,27 @@ const router = createRouter({
|
||||
{
|
||||
path: '/',
|
||||
name: 'browse',
|
||||
component: Browse
|
||||
component: Browse,
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
{
|
||||
path: '/library',
|
||||
name: 'library',
|
||||
component: () => import('../views/Library.vue'),
|
||||
beforeEnter: authGuard,
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
component: () => import('../views/Profile.vue'),
|
||||
beforeEnter: authGuard,
|
||||
meta: { requiresAuth: true }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// Setup authentication guards
|
||||
setupGuards(router)
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user