Altera login, add cookie e comeca lista de videos

This commit is contained in:
LeoMortari
2025-09-18 11:44:33 -03:00
parent 8577add91e
commit 2e65d38222
5 changed files with 85 additions and 140 deletions

View File

@@ -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();
});