Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 348c9771
authored
Nov 03, 2025
by
Jin Mao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Revert "refactor(jwt): 更新 JWT 工具函数实现方式 (#6869)"
This reverts commit
a854760d
.
1 parent
a854760d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
apps/backend-mock/utils/jwt-utils.ts
apps/backend-mock/utils/jwt-utils.ts
View file @
348c977
...
@@ -3,7 +3,7 @@ import type { EventHandlerRequest, H3Event } from 'h3';
...
@@ -3,7 +3,7 @@ import type { EventHandlerRequest, H3Event } from 'h3';
import
type
{
UserInfo
}
from
'./mock-data'
;
import
type
{
UserInfo
}
from
'./mock-data'
;
import
{
getHeader
}
from
'h3'
;
import
{
getHeader
}
from
'h3'
;
import
{
sign
,
verify
}
from
'jsonwebtoken'
;
import
jwt
from
'jsonwebtoken'
;
import
{
MOCK_USERS
}
from
'./mock-data'
;
import
{
MOCK_USERS
}
from
'./mock-data'
;
...
@@ -17,11 +17,11 @@ export interface UserPayload extends UserInfo {
...
@@ -17,11 +17,11 @@ export interface UserPayload extends UserInfo {
}
}
export
function
generateAccessToken
(
user
:
UserInfo
)
{
export
function
generateAccessToken
(
user
:
UserInfo
)
{
return
sign
(
user
,
ACCESS_TOKEN_SECRET
,
{
expiresIn
:
'7d'
});
return
jwt
.
sign
(
user
,
ACCESS_TOKEN_SECRET
,
{
expiresIn
:
'7d'
});
}
}
export
function
generateRefreshToken
(
user
:
UserInfo
)
{
export
function
generateRefreshToken
(
user
:
UserInfo
)
{
return
sign
(
user
,
REFRESH_TOKEN_SECRET
,
{
return
jwt
.
sign
(
user
,
REFRESH_TOKEN_SECRET
,
{
expiresIn
:
'30d'
,
expiresIn
:
'30d'
,
});
});
}
}
...
@@ -40,7 +40,7 @@ export function verifyAccessToken(
...
@@ -40,7 +40,7 @@ export function verifyAccessToken(
}
}
const
token
=
tokenParts
[
1
]
as
string
;
const
token
=
tokenParts
[
1
]
as
string
;
try
{
try
{
const
decoded
=
verify
(
const
decoded
=
jwt
.
verify
(
token
,
token
,
ACCESS_TOKEN_SECRET
,
ACCESS_TOKEN_SECRET
,
)
as
unknown
as
UserPayload
;
)
as
unknown
as
UserPayload
;
...
@@ -61,7 +61,7 @@ export function verifyRefreshToken(
...
@@ -61,7 +61,7 @@ export function verifyRefreshToken(
token
:
string
,
token
:
string
,
):
null
|
Omit
<
UserInfo
,
'password'
>
{
):
null
|
Omit
<
UserInfo
,
'password'
>
{
try
{
try
{
const
decoded
=
verify
(
token
,
REFRESH_TOKEN_SECRET
)
as
UserPayload
;
const
decoded
=
jwt
.
verify
(
token
,
REFRESH_TOKEN_SECRET
)
as
UserPayload
;
const
username
=
decoded
.
username
;
const
username
=
decoded
.
username
;
const
user
=
MOCK_USERS
.
find
(
const
user
=
MOCK_USERS
.
find
(
(
item
)
=>
item
.
username
===
username
,
(
item
)
=>
item
.
username
===
username
,
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment