1
0
Fork 0
mirror of https://github.com/requarks/wiki.git synced 2026-03-02 22:06:55 -05:00

Failed refreshToken in jwt should be considered as the same as invalid JWT token #1380

Open
opened 2026-02-20 18:08:48 -05:00 by deekerman · 0 comments
Owner

Originally created by @quangld on GitHub (Apr 16, 2020).

Originally assigned to: @NGPixel on GitHub.

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

Originally created by @quangld on GitHub (Apr 16, 2020). Originally assigned to: @NGPixel on GitHub. 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
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/wiki-requarks#1380
No description provided.