Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
web-monitor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
web-monitor
Commits
822c59bd
Commit
822c59bd
authored
7 years ago
by
Pan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cookie token bug
parent
4321f584
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
7 deletions
+24
-7
main.js
src/main.js
+2
-1
user.js
src/store/modules/user.js
+5
-5
auth.js
src/utils/auth.js
+15
-0
fetch.js
src/utils/fetch.js
+2
-1
No files found.
src/main.js
View file @
822c59bd
...
...
@@ -11,6 +11,7 @@ import 'nprogress/nprogress.css'
import
'normalize.css/normalize.css'
import
'@/assets/iconfont/iconfont'
import
IconSvg
from
'@/components/Icon-svg/index.vue'
import
{
getToken
}
from
'@/utils/auth'
Vue
.
config
.
productionTip
=
false
...
...
@@ -20,7 +21,7 @@ Vue.component('icon-svg', IconSvg)
const
whiteList
=
[
'/login'
];
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
NProgress
.
start
();
if
(
store
.
getters
.
token
)
{
if
(
getToken
()
)
{
if
(
to
.
path
===
'/login'
)
{
next
({
path
:
'/'
});
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/store/modules/user.js
View file @
822c59bd
import
{
login
,
logout
,
getInfo
}
from
'@/api/login'
;
import
Cookies
from
'js-cookie
'
;
import
{
getToken
,
setToken
,
removeToken
}
from
'@/utils/auth
'
;
const
user
=
{
state
:
{
token
:
Cookies
.
get
(
'Admin-Token'
),
token
:
getToken
(
),
name
:
''
,
avatar
:
''
,
roles
:
[]
...
...
@@ -31,7 +31,7 @@ const user = {
return
new
Promise
((
resolve
,
reject
)
=>
{
login
(
email
,
userInfo
.
password
).
then
(
response
=>
{
const
data
=
response
.
data
;
Cookies
.
set
(
'Admin-Token'
,
data
.
token
);
setToken
(
data
.
token
);
commit
(
'SET_TOKEN'
,
data
.
token
);
resolve
();
}).
catch
(
error
=>
{
...
...
@@ -62,7 +62,7 @@ const user = {
logout
(
state
.
token
).
then
(()
=>
{
commit
(
'SET_TOKEN'
,
''
);
commit
(
'SET_ROLES'
,
[]);
Cookies
.
remove
(
'Admin-Token'
);
removeToken
(
);
resolve
();
}).
catch
(
error
=>
{
reject
(
error
);
...
...
@@ -74,7 +74,7 @@ const user = {
FedLogOut
({
commit
})
{
return
new
Promise
(
resolve
=>
{
commit
(
'SET_TOKEN'
,
''
);
Cookies
.
remove
(
'Admin-Token'
);
removeToken
(
);
resolve
();
});
}
...
...
This diff is collapsed.
Click to expand it.
src/utils/auth.js
0 → 100644
View file @
822c59bd
import
Cookies
from
'js-cookie'
const
TokenKey
=
'Admin-Token'
export
function
getToken
()
{
return
Cookies
.
get
(
TokenKey
)
}
export
function
setToken
(
token
)
{
return
Cookies
.
set
(
TokenKey
,
token
)
}
export
function
removeToken
()
{
return
Cookies
.
remove
(
TokenKey
)
}
This diff is collapsed.
Click to expand it.
src/utils/fetch.js
View file @
822c59bd
import
axios
from
'axios'
;
import
{
Message
}
from
'element-ui'
;
import
store
from
'../store'
;
import
{
getToken
}
from
'@/utils/auth'
;
// 创建axios实例
...
...
@@ -12,7 +13,7 @@ const service = axios.create({
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
if
(
store
.
getters
.
token
)
{
config
.
headers
[
'X-Token'
]
=
store
.
getters
.
token
;
// 让每个请求携带自定义token 请根据实际情况自行修改
config
.
headers
[
'X-Token'
]
=
getToken
()
;
// 让每个请求携带自定义token 请根据实际情况自行修改
}
return
config
;
},
error
=>
{
...
...
This diff is collapsed.
Click to expand it.
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