mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 15:21:14 +00:00
V2 alpha - initial version (#172)
Initial alpha codebase for version 2 of WireGuard Portal. This version is considered unstable and incomplete (for example, no public REST API)! Use with care! Fixes/Implements the following issues: - OAuth support #154, #1 - New Web UI with internationalisation support #98, #107, #89, #62 - Postgres Support #49 - Improved Email handling #47, #119 - DNS Search Domain support #46 - Bugfixes #94, #48 --------- Co-authored-by: Fabian Wechselberger <wechselbergerf@hotmail.com>
This commit is contained in:
109
frontend/src/router/index.js
Normal file
109
frontend/src/router/index.js
Normal file
@@ -0,0 +1,109 @@
|
||||
import {createRouter, createWebHashHistory} from 'vue-router'
|
||||
import HomeView from '../views/HomeView.vue'
|
||||
import LoginView from '../views/LoginView.vue'
|
||||
import InterfaceView from '../views/InterfaceView.vue'
|
||||
|
||||
import {authStore} from '@/stores/auth'
|
||||
import {notify} from "@kyvg/vue3-notification";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomeView
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: LoginView
|
||||
},
|
||||
{
|
||||
path: '/interface',
|
||||
name: 'interface',
|
||||
component: InterfaceView
|
||||
},
|
||||
{
|
||||
path: '/interfaces',
|
||||
name: 'interfaces',
|
||||
// route level code-splitting
|
||||
// this generates a separate chunk (About.[hash].js) for this route
|
||||
// which is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/InterfaceView.vue')
|
||||
},
|
||||
{
|
||||
path: '/users',
|
||||
name: 'users',
|
||||
// route level code-splitting
|
||||
// this generates a separate chunk (About.[hash].js) for this route
|
||||
// which is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/UserView.vue')
|
||||
},
|
||||
{
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
// route level code-splitting
|
||||
// this generates a separate chunk (About.[hash].js) for this route
|
||||
// which is lazy-loaded when the route is visited.
|
||||
component: () => import('../views/ProfileView.vue')
|
||||
}
|
||||
],
|
||||
linkActiveClass: "active",
|
||||
linkExactActiveClass: "exact-active",
|
||||
})
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
const auth = authStore()
|
||||
|
||||
// check if the request was a successful oauth login
|
||||
if ('wgLoginState' in to.query && !auth.IsAuthenticated) {
|
||||
const state = to.query['wgLoginState']
|
||||
const returnUrl = auth.ReturnUrl
|
||||
console.log("Oauth login callback:", state)
|
||||
|
||||
if (state === "success") {
|
||||
try {
|
||||
const uid = await auth.LoadSession()
|
||||
console.log("Oauth login completed for UID:", uid)
|
||||
console.log("Continuing to:", returnUrl)
|
||||
|
||||
notify({
|
||||
title: "Logged in",
|
||||
text: "Authentication suceeded!",
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
auth.ResetReturnUrl()
|
||||
return returnUrl
|
||||
} catch (e) {
|
||||
notify({
|
||||
title: "Login failed!",
|
||||
text: "Oauth session is invalid!",
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
return '/login'
|
||||
}
|
||||
} else {
|
||||
notify({
|
||||
title: "Login failed!",
|
||||
text: "Authentication via Oauth failed!",
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
return '/login'
|
||||
}
|
||||
}
|
||||
|
||||
// redirect to login page if not logged in and trying to access a restricted page
|
||||
const publicPages = ['/', '/login']
|
||||
const authRequired = !publicPages.includes(to.path)
|
||||
|
||||
if (authRequired && !auth.IsAuthenticated) {
|
||||
auth.SetReturnUrl(to.fullPath) // store original destination before starting the auth process
|
||||
return '/login'
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
Reference in New Issue
Block a user