diff --git a/README.md b/README.md index 980a9f1..8fbf7b0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Zac-Mainframe +# Zac-Mainframe-Front **A great Web Interface to manage my own developed software.** diff --git a/package.json b/package.json index f9aa7ea..23e2250 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "zac-mainframe", - "version": "0.0.1", + "name": "zac-mainframe-front", + "version": "0.0.2", "private": true, "type": "module", "scripts": { diff --git a/src/main.ts b/src/main.ts index 7320b9b..12249fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,18 +1,18 @@ -import { createApp } from 'vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { library } from '@fortawesome/fontawesome-svg-core' import { fas } from '@fortawesome/free-solid-svg-icons' import { fab } from '@fortawesome/free-brands-svg-icons' +import { createApp } from 'vue' +import cookies from 'vue-cookies' import App from './App.vue' import router from './router' -import cookies from 'vue-cookies' import './assets/main.css' library.add(fas, fab) createApp(App) .use(router) - .use(cookies, { expires: '1d' }) + .use(cookies) .component('font-awesome-icon', FontAwesomeIcon) .mount('#app') diff --git a/src/router/index.ts b/src/router/index.ts index 81d522b..77c4687 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,12 +1,6 @@ import { createRouter, createWebHistory } from 'vue-router' - -import IndexView from '../views/IndexView.vue' -import HomeView from '../views/Index/HomeView.vue' -import AboutView from '../views/Index/AboutView.vue' - -import DiscordView from '../views/DiscordView.vue' -import DashboardView from '../views/Discord/DashboardView.vue' -import ConfigView from '../views/Discord/ConfigView.vue' +import { inject } from 'vue' +import type { VueCookies } from 'vue-cookies' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -14,38 +8,50 @@ const router = createRouter({ { path: '/', name: 'index', - component: IndexView, + component: () => import('../views/IndexView.vue'), children: [ { path: '', name: 'home', - component: HomeView + component: () => import('../views/Index/HomeView.vue') }, { path: '/about', name: 'about', - component: AboutView + component: () => import('../views/Index/AboutView.vue') } ] }, { path: '/discord', name: 'discord', - component: DiscordView, + component: () => import('../views/DiscordView.vue'), + meta: { discordAuth: true }, children: [ { path: '', name: 'dashboard', - component: DashboardView + component: () => import('../views/Discord/DashboardView.vue') }, { path: '/config', name: 'config', - component: ConfigView + component: () => import('../views/Discord/ConfigView.vue') } ] } ] }) +router.beforeEach((to) => { + const $cookies = inject('$cookies') + if (!$cookies) return console.log('Error: $cookies is not injected') + + if (to.meta.discordAuth && !$cookies.isKey('DISCORD_CODE')) { + window.location.href = + 'https://discord.com/oauth2/authorize?client_id=1274800564449841172&response_type=code&redirect_uri=https%3A%2F%2Fmainframe.zac.ovh%2Fdiscord&scope=identify' + return + } +}) + export default router diff --git a/src/views/DiscordView.vue b/src/views/DiscordView.vue index 11d08ce..a886c45 100644 --- a/src/views/DiscordView.vue +++ b/src/views/DiscordView.vue @@ -1,5 +1,13 @@