Failed refreshToken in jwt should be considered as the same as invalid JWT token
Open
@NGPixel is already working on this.
Since Apr 17, 2020.
enhancement
- Dominant language
- Vue
- Stars
- 28.9k
- Forks
- 3.3k
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
if the refreshToken fails in this below code, it throws new WIKI.Error.AuthGenericError(). This will show the internal error on user's screen.
function authenticate in server\core\auth.js
// Expired but still valid within N days, just renew
...
try {
const newToken = await WIKI.models.users.refreshToken(jwtPayload.id)
...
} catch (errc) {
WIKI.logger.warn(errc)
**return next()**
}
}
// JWT is NOT valid, set as guest
if (!user) {
...
}
My suggestion is to set user to null, skip next(). That means the token is considered invalid.
// Expired but still valid within N days, just renew
...
try {
const newToken = await WIKI.models.users.refreshToken(jwtPayload.id)
...
} catch (errc) {
WIKI.logger.warn(errc)
// return next()
user = null // JWT token is invalid, continue with no user is set
}
}
// JWT is NOT valid, set as guest
if (!user) {
...
}
Edited: fix formatting
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.