Skip to content

Commit 3b3d26e

Browse files
mamicocekk
andauthored
fix: verify token expired (#2)
* fix: verify token expired * debug condition * debug * debug * debug * fix typo * fix condition * debug --------- Co-authored-by: Andrea Cecchi <andrea.cecchi85@gmail.com>
1 parent f87505d commit 3b3d26e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,19 @@ const applyConfig = (config) => {
4040
}
4141
if (token && settings?.userHeaderName) {
4242
const user = req.get(settings.userHeaderName);
43-
if (user && jwtDecode(token).sub !== user) {
43+
// require auth if:
44+
// - header user is different from token user
45+
// - token has no expiration
46+
// - token is expired
47+
console.log("USER: ", user);
48+
console.log("TOKEN: ", jwtDecode(token));
49+
console.log("TOKEN SCADUTO: ", jwtDecode(token).exp < Date.now() / 1000);
50+
console.log("CONDIZIONE: ", ((user && jwtDecode(token).sub !== user) || !jwtDecode(token).exp || jwtDecode(token).exp < Date.now() / 1000));
51+
if ((user && jwtDecode(token).sub !== user) || !jwtDecode(token).exp || jwtDecode(token).exp < Date.now() / 1000){
52+
// TODO: eventually add base_url to a relative settings.loginUrl
4453
return res.redirect(`${settings.loginUrl}?came_from=${req.url}`);
4554
}
55+
4656
}
4757
}
4858
return next();

0 commit comments

Comments
 (0)