Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yizhi_server
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
data_server
yizhi_server
Commits
fdf34ed3
Commit
fdf34ed3
authored
Apr 23, 2020
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录token问题
parent
b7d4be71
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
authInit.js
app/middleware/authInit.js
+2
-3
jwt.js
app/service/jwt.js
+3
-2
No files found.
app/middleware/authInit.js
View file @
fdf34ed3
...
@@ -10,9 +10,8 @@ module.exports = () => {
...
@@ -10,9 +10,8 @@ module.exports = () => {
}
}
const
token_black
=
await
ctx
.
app
.
memcache
.
get
(
'yizhi_server_token'
+
token_data
.
data
.
user_id
);
const
token_black
=
await
ctx
.
app
.
memcache
.
get
(
'yizhi_server_token'
+
token_data
.
data
.
user_id
);
// ctx.logger.info('【token_black:】', token_black, token);
// ctx.logger.info('【token_black:】', token_black, token);
if
(
token_black
)
ctx
.
app
.
logger
.
info
(
'【sso token black:】'
,
token_black
,
token
);
if
(
token_black
!==
token
)
{
if
(
token_black
===
token
)
{
ctx
.
failed
(
'无效的token'
);
ctx
.
failed
(
'token 已失效'
);
}
}
ctx
.
token
=
token
||
''
;
ctx
.
token
=
token
||
''
;
ctx
.
userId
=
token_data
.
data
.
user_id
||
''
;
ctx
.
userId
=
token_data
.
data
.
user_id
||
''
;
...
...
app/service/jwt.js
View file @
fdf34ed3
...
@@ -5,7 +5,7 @@ const Service = require('egg').Service;
...
@@ -5,7 +5,7 @@ const Service = require('egg').Service;
class
JwtService
extends
Service
{
class
JwtService
extends
Service
{
async
apply
(
data
)
{
async
apply
(
data
)
{
const
{
ctx
}
=
this
;
const
{
ctx
,
config
,
app
}
=
this
;
const
exp
=
Math
.
round
(
new
Date
().
getTime
()
/
1000
)
+
ctx
.
app
.
config
.
jwtExp
;
const
exp
=
Math
.
round
(
new
Date
().
getTime
()
/
1000
)
+
ctx
.
app
.
config
.
jwtExp
;
const
secret
=
ctx
.
app
.
config
.
jwt
.
secret
;
const
secret
=
ctx
.
app
.
config
.
jwt
.
secret
;
const
auth_token
=
ctx
.
app
.
jwt
.
sign
(
const
auth_token
=
ctx
.
app
.
jwt
.
sign
(
...
@@ -15,6 +15,7 @@ class JwtService extends Service {
...
@@ -15,6 +15,7 @@ class JwtService extends Service {
},
},
secret
secret
);
);
await
app
.
memcache
.
set
(
'yizhi_server_token'
+
data
.
user_id
,
auth_token
,
config
.
jwtExp
);
return
auth_token
;
return
auth_token
;
}
}
...
@@ -28,7 +29,7 @@ class JwtService extends Service {
...
@@ -28,7 +29,7 @@ class JwtService extends Service {
const
{
app
,
config
}
=
this
;
const
{
app
,
config
}
=
this
;
const
token_data
=
await
this
.
decode_token
(
token
);
const
token_data
=
await
this
.
decode_token
(
token
);
const
{
user_id
}
=
token_data
.
data
;
const
{
user_id
}
=
token_data
.
data
;
await
app
.
memcache
.
set
(
'yizhi_server_token'
+
user_id
,
token
,
config
.
jwtExp
);
await
app
.
memcache
.
set
(
'yizhi_server_token'
+
user_id
,
''
,
config
.
jwtExp
);
return
true
;
return
true
;
}
}
}
}
...
...
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