Skip to content

Commit

Permalink
fix: verify token expired
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Feb 1, 2024
1 parent bc475fc commit 4c73da9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ const applyConfig = (config) => {
}
if (token && settings?.userHeaderName) {
const user = req.get(settings.userHeaderName);
if (user && jwtDecode(token).sub !== user) {
// require auth if:
// - header user is different from token user
// - token has no expiration
// - token is expired
if (jwtDecode(token).sub !== user || !jwtDecode(token).exp || jwtDecode(token).exp < Date.now() / 1000){
// TODO: eventually add base_url to a relative settings.loginUrl
return res.redirect(`${settings.loginUrl}?came_from=${req.url}`);
}

}
}
return next();
Expand Down

0 comments on commit 4c73da9

Please sign in to comment.