2019-04-15 16:50:38 +02:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Router from 'vue-router'
|
2022-07-03 13:05:17 +02:00
|
|
|
import { isAuthenticated } from './services/auth.js'
|
2019-04-15 16:50:38 +02:00
|
|
|
|
|
|
|
Vue.use(Router)
|
|
|
|
|
2020-05-24 11:50:21 +02:00
|
|
|
const router = new Router({
|
2020-12-30 11:11:40 +01:00
|
|
|
base: process.env.BASE_URL,
|
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'dashboard',
|
2022-07-04 14:13:13 +02:00
|
|
|
component: () => import('./views/Dashboard.vue')
|
2020-12-30 11:11:40 +01:00
|
|
|
},
|
2022-07-03 13:05:17 +02:00
|
|
|
{
|
|
|
|
path: '/settings',
|
|
|
|
name: 'settings',
|
2022-07-04 14:13:13 +02:00
|
|
|
component: () => import('./views/Settings.vue')
|
2022-07-03 13:05:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/torrent/:hash',
|
|
|
|
name: 'torrentDetail',
|
2022-07-04 14:13:13 +02:00
|
|
|
component: () => import('./views/TorrentDetail.vue')
|
2022-07-03 13:05:17 +02:00
|
|
|
},
|
2021-01-30 13:26:06 +01:00
|
|
|
{ path: '/download=:magnet',
|
|
|
|
name: 'MagnetHandler',
|
2022-07-04 14:13:13 +02:00
|
|
|
component: () => import('./views/MagnetHandler.vue'),
|
2021-01-30 13:26:06 +01:00
|
|
|
props: true
|
|
|
|
},
|
2020-12-30 11:11:40 +01:00
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
name: 'login',
|
2022-07-04 14:13:13 +02:00
|
|
|
component: () => import('./views/Login.vue'),
|
2020-12-30 11:11:40 +01:00
|
|
|
meta: {
|
2021-08-29 11:26:13 +02:00
|
|
|
public: true // Allow access to even if not logged in }
|
2020-12-30 11:11:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2019-04-15 16:50:38 +02:00
|
|
|
})
|
2020-05-22 11:41:48 +02:00
|
|
|
|
2020-05-24 11:50:21 +02:00
|
|
|
router.beforeEach(async (to, from, next) => {
|
2020-12-30 11:11:40 +01:00
|
|
|
const isPublic = to.matched.some(record => record.meta.public)
|
|
|
|
const authenticated = isAuthenticated()
|
2020-05-24 11:50:21 +02:00
|
|
|
|
2020-12-30 11:11:40 +01:00
|
|
|
if (!isPublic && !authenticated) {
|
|
|
|
return next({
|
|
|
|
path: '/login',
|
|
|
|
// Store the full path to redirect the user to after login
|
|
|
|
query: { redirect: to.fullPath }
|
|
|
|
})
|
|
|
|
}
|
2020-05-24 11:50:21 +02:00
|
|
|
|
2020-12-30 11:11:40 +01:00
|
|
|
next()
|
2020-05-24 11:50:21 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export default router
|