Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alba María Álvarez
/
front_recipes
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
06158f8a
authored
Aug 26, 2025
by
Alba María Álvarez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat(index.js): añadidas restricciones de acceso para usuarios no autenticados
parent
8c0af869
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
6 deletions
src/router/index.js
src/router/index.js
View file @
06158f8a
...
...
@@ -7,6 +7,7 @@ import CreateRecipe from '@/views/CreateRecipe.vue'
import
RecipeDetail
from
'@/views/RecipeDetail.vue'
import
UserDetail
from
'@/views/UserDetail.vue'
import
UserManagement
from
'@/views/UserManagement.vue'
import
{
useAuthStore
}
from
'@/stores/authStore'
const
routes
=
[
{
...
...
@@ -26,32 +27,38 @@ const routes = [
{
path
:
'/recipes/search'
,
name
:
'AISearch'
,
component
:
AISearch
component
:
AISearch
,
meta
:
{
requiresAuth
:
true
}
},
{
path
:
'/recipes'
,
name
:
'Recipes'
,
component
:
Recipes
component
:
Recipes
,
meta
:
{
requiresAuth
:
true
}
},
{
path
:
'/recipes/create'
,
name
:
'CreateRecipe'
,
component
:
CreateRecipe
component
:
CreateRecipe
,
meta
:
{
requiresAuth
:
true
}
},
{
path
:
'/recipes/detail'
,
name
:
'RecipeDetail'
,
component
:
RecipeDetail
component
:
RecipeDetail
,
meta
:
{
requiresAuth
:
true
}
},
{
path
:
'/users/detail'
,
name
:
'UserDetail'
,
component
:
UserDetail
component
:
UserDetail
,
meta
:
{
requiresAuth
:
true
}
},
{
path
:
'/users/management'
,
name
:
'UserManagement'
,
component
:
UserManagement
component
:
UserManagement
,
meta
:
{
requiresAuth
:
true
}
}
]
...
...
@@ -60,4 +67,18 @@ const router = createRouter({
routes
,
})
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
authStore
=
useAuthStore
();
const
requiresAuth
=
to
.
matched
.
some
(
record
=>
record
.
meta
.
requiresAuth
);
// Si el usuario no está autenticado
if
(
requiresAuth
&&
!
authStore
.
isAuthenticated
)
{
next
({
path
:
'/auth/login'
});
}
else
{
next
();
}
// Si el usuario no es ADMIN ...
})
export
default
router
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment