From 2e65d38222ef34da42fe316874d394c36b6a7d15 Mon Sep 17 00:00:00 2001 From: LeoMortari Date: Thu, 18 Sep 2025 11:44:33 -0300 Subject: [PATCH] Altera login, add cookie e comeca lista de videos --- src/App.vue | 23 +++++-- src/auth/router.js | 51 ++++++++------- src/config/axios.js | 3 +- src/routes/auth/Login.vue | 23 +++++-- src/routes/videos/index.vue | 125 ++++++------------------------------ 5 files changed, 85 insertions(+), 140 deletions(-) diff --git a/src/App.vue b/src/App.vue index d10e643..82cbaf3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,7 +8,13 @@ - +
Clipper AI @@ -18,8 +24,13 @@ - - {{ route.title }} + + {{ route.meta.title }} @@ -61,11 +72,11 @@ export default { computed: { currentRouteTitle() { const route = this.$route; - return route.meta?.title || route.name || 'Clipper AI'; + return route.meta?.title || route.name || "Clipper AI"; }, isLoginPage() { - return this.$route.path === '/login'; - } + return this.$route.path === "/login"; + }, }, }; diff --git a/src/auth/router.js b/src/auth/router.js index a370db1..46d127a 100644 --- a/src/auth/router.js +++ b/src/auth/router.js @@ -31,18 +31,24 @@ export const routes = [ requiresAuth: true, title: "VĂ­deos", permissions: [roles.VIDEOS_LIST], + showinModal: true, }, }, { path: "/:pathMatch(.*)*", + meta: { + showinModal: false, + }, redirect: (to) => { return Cookies.get("token") ? "/videos" : "/login"; }, }, { path: "/", + meta: { + showinModal: false, + }, redirect: (to) => { - console.log(Cookies); return Cookies.get("token") ? "/videos" : "/login"; }, }, @@ -69,32 +75,33 @@ const hasPermission = (requiredPermissions = []) => { router.beforeEach((to, from, next) => { if (to.meta.title) { - document.title = `${to.meta.title} | ClipperIA`; + document.title = to.meta.title; } - if (to.matched.some((record) => record.meta.requiresAuth)) { - if (!isAuthenticated()) { - next({ - path: "/login", - query: { redirect: to.fullPath }, - }); - return; - } - - const requiredPermissions = to.meta.permissions || []; - - if (requiredPermissions.length > 0 && !hasPermission(requiredPermissions)) { - next({ path: "/unauthorized" }); - - return; - } - } - - if (to.matched.some((record) => record.meta.guest) && isAuthenticated()) { - next({ path: "/" }); + // if (to.matched.some((record) => record.meta.requiresAuth)) { + if (!isAuthenticated()) { + next({ + path: "/login", + query: { redirect: to.fullPath }, + }); return; } + // const requiredPermissions = to.meta.permissions || []; + + // if (requiredPermissions.length > 0 && !hasPermission(requiredPermissions)) { + // next({ path: "/unauthorized" }); + + // return; + // } + // } + + // if (to.matched.some((record) => record.meta.guest) && isAuthenticated()) { + // next({ path: "/" }); + + // return; + // } + next(); }); diff --git a/src/config/axios.js b/src/config/axios.js index d4b43a9..03df154 100644 --- a/src/config/axios.js +++ b/src/config/axios.js @@ -1,4 +1,5 @@ import axios from "axios"; +import Cookies from "js-cookie"; export const API = axios.create({ baseURL: @@ -8,7 +9,7 @@ export const API = axios.create({ }); API.interceptors.request.use((config) => { - const token = localStorage.getItem("token"); + const token = Cookies.get("token"); if (token) { config.headers.Authorization = `Bearer ${token}`; diff --git a/src/routes/auth/Login.vue b/src/routes/auth/Login.vue index 39dc1b5..11fb4d8 100644 --- a/src/routes/auth/Login.vue +++ b/src/routes/auth/Login.vue @@ -1,5 +1,5 @@