Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boco-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106_2022_02
boco-frontend
Commits
fdafdd03
Commit
fdafdd03
authored
3 years ago
by
Titus Netland
Browse files
Options
Downloads
Patches
Plain Diff
Guard routes renamed
parent
4b9f69c0
No related branches found
No related tags found
1 merge request
!159
Router update 2
Pipeline
#182397
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/router/index.js
+18
-18
18 additions, 18 deletions
src/router/index.js
with
18 additions
and
18 deletions
src/router/index.js
+
18
−
18
View file @
fdafdd03
...
@@ -3,12 +3,12 @@ import { createRouter, createWebHistory } from "vue-router";
...
@@ -3,12 +3,12 @@ import { createRouter, createWebHistory } from "vue-router";
import
NotFound
from
"
@/views/NotFound.vue
"
;
import
NotFound
from
"
@/views/NotFound.vue
"
;
/**
/**
* Guard
s
routes.
* Guard route
for logged-in user
s.
* If token is null, no user is logged in and only the
* If token is null, no user is logged in and only the
* login, register, reset password, help and listing of public groups and items pages will be accessible.
* login, register, reset password, help and listing of public groups and items pages will be accessible.
* Without a token the user gets redirected to the login page when trying to access guard routed pages.
* Without a token the user gets redirected to the login page when trying to access guard routed pages.
*/
*/
function
g
uardRoute
(
to
,
from
,
next
)
{
function
authG
uardRoute
(
to
,
from
,
next
)
{
let
isAuthenticated
=
store
.
state
.
user
.
token
!=
null
;
let
isAuthenticated
=
store
.
state
.
user
.
token
!=
null
;
if
(
isAuthenticated
)
{
if
(
isAuthenticated
)
{
next
();
// allow to enter route
next
();
// allow to enter route
...
@@ -18,10 +18,10 @@ function guardRoute(to, from, next) {
...
@@ -18,10 +18,10 @@ function guardRoute(to, from, next) {
}
}
/**
/**
* Guards route
s
for administartors. If token is null or
* Guards route for administartors. If token is null or
* the user is not the administrator of the group, the user gets sent to the home page.
* the user is not the administrator of the group, the user gets sent to the home page.
*/
*/
function
isA
dmin
(
to
,
from
,
next
)
{
function
a
dmin
GuardRoute
(
to
,
from
,
next
)
{
if
(
store
.
state
.
user
.
adminList
.
includes
(
parseInt
(
from
.
params
.
communityID
)))
if
(
store
.
state
.
user
.
adminList
.
includes
(
parseInt
(
from
.
params
.
communityID
)))
next
();
// allow to enter route
next
();
// allow to enter route
else
else
...
@@ -44,19 +44,19 @@ const routes = [
...
@@ -44,19 +44,19 @@ const routes = [
path
:
"
/community/:communityID/admin
"
,
path
:
"
/community/:communityID/admin
"
,
name
:
"
communityAdminPage
"
,
name
:
"
communityAdminPage
"
,
component
:
()
=>
import
(
"
@/views/CommunityViews/AdminView.vue
"
),
component
:
()
=>
import
(
"
@/views/CommunityViews/AdminView.vue
"
),
beforeEnter
:
[
g
uardRoute
,
isA
dmin
],
beforeEnter
:
[
authG
uardRoute
,
a
dmin
GuardRoute
],
},
},
{
{
path
:
"
/community/:communityID/memberlist
"
,
path
:
"
/community/:communityID/memberlist
"
,
name
:
"
memberlist
"
,
name
:
"
memberlist
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/MemberListView.vue
"
),
component
:
()
=>
import
(
"
../views/CommunityViews/MemberListView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/community/:communityID/private/join
"
,
path
:
"
/community/:communityID/private/join
"
,
name
:
"
communityRequest
"
,
name
:
"
communityRequest
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/CommunityRequestView.vue
"
),
component
:
()
=>
import
(
"
../views/CommunityViews/CommunityRequestView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/help
"
,
path
:
"
/help
"
,
...
@@ -67,13 +67,13 @@ const routes = [
...
@@ -67,13 +67,13 @@ const routes = [
path
:
"
/item/:id
"
,
path
:
"
/item/:id
"
,
name
:
"
itemInfo
"
,
name
:
"
itemInfo
"
,
component
:
()
=>
import
(
"
../views/RentingViews/ItemInfoPageView.vue
"
),
component
:
()
=>
import
(
"
../views/RentingViews/ItemInfoPageView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/item/:id/edit
"
,
path
:
"
/item/:id/edit
"
,
name
:
"
editItem
"
,
name
:
"
editItem
"
,
component
:
()
=>
import
(
"
../views/ItemViews/EditItemView.vue
"
),
component
:
()
=>
import
(
"
../views/ItemViews/EditItemView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/login
"
,
path
:
"
/login
"
,
...
@@ -84,49 +84,49 @@ const routes = [
...
@@ -84,49 +84,49 @@ const routes = [
path
:
"
/messages
"
,
path
:
"
/messages
"
,
name
:
"
messages
"
,
name
:
"
messages
"
,
component
:
()
=>
import
(
"
../views/ChatViews/ChatView.vue
"
),
component
:
()
=>
import
(
"
../views/ChatViews/ChatView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/newCommunity
"
,
path
:
"
/newCommunity
"
,
name
:
"
newCommunity
"
,
name
:
"
newCommunity
"
,
component
:
()
=>
import
(
"
../views/CommunityViews/NewCommunityView.vue
"
),
component
:
()
=>
import
(
"
../views/CommunityViews/NewCommunityView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/newItem
"
,
path
:
"
/newItem
"
,
name
:
"
newItem
"
,
name
:
"
newItem
"
,
component
:
()
=>
import
(
"
../views/ItemViews/NewItemView.vue
"
),
component
:
()
=>
import
(
"
../views/ItemViews/NewItemView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/newPassword
"
,
path
:
"
/newPassword
"
,
name
:
"
newPassword
"
,
name
:
"
newPassword
"
,
component
:
()
=>
import
(
"
../views/UserAuthViews/NewPasswordView
"
),
component
:
()
=>
import
(
"
../views/UserAuthViews/NewPasswordView
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/profile/:id
"
,
path
:
"
/profile/:id
"
,
name
:
"
profile
"
,
name
:
"
profile
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/ProfileView.vue
"
),
component
:
()
=>
import
(
"
../views/UserProfileViews/ProfileView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/profile/communities
"
,
path
:
"
/profile/communities
"
,
name
:
"
myCommunities
"
,
name
:
"
myCommunities
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/MyCommunitiesView.vue
"
),
component
:
()
=>
import
(
"
../views/UserProfileViews/MyCommunitiesView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/profile/history
"
,
path
:
"
/profile/history
"
,
name
:
"
history
"
,
name
:
"
history
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/RentHistoryView.vue
"
),
component
:
()
=>
import
(
"
../views/UserProfileViews/RentHistoryView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/profile/items
"
,
path
:
"
/profile/items
"
,
name
:
"
userItems
"
,
name
:
"
userItems
"
,
component
:
()
=>
import
(
"
../views/UserProfileViews/UserItemsView.vue
"
),
component
:
()
=>
import
(
"
../views/UserProfileViews/UserItemsView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
{
{
path
:
"
/register
"
,
path
:
"
/register
"
,
...
@@ -147,7 +147,7 @@ const routes = [
...
@@ -147,7 +147,7 @@ const routes = [
path
:
"
/test
"
,
path
:
"
/test
"
,
name
:
"
test
"
,
name
:
"
test
"
,
component
:
()
=>
import
(
"
../views/TestView.vue
"
),
component
:
()
=>
import
(
"
../views/TestView.vue
"
),
beforeEnter
:
g
uardRoute
,
beforeEnter
:
authG
uardRoute
,
},
},
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment