fix: jwt.verify handles expiration

This commit is contained in:
Apoorv Mishra committed 2023-09-09 08:06:53 +05:30
1 parent dc5c90b69a
commit 8c30c3fb10
2 files changed
+4 -11

No files matched your search

+4 -4
View File
@@ -85,12 +85,12 @@ export default class LocalStorage extends BaseStorage {
const sig = JWT.sign(
{
key,
expiresAt: expiresIn
? new Date(Date.now() + expiresIn * 1000)
: undefined,
type: "attachment",
},
env.SECRET_KEY
env.SECRET_KEY,
{
expiresIn,
}
);
return Promise.resolve(`/api/files.get?sig=${sig}`);
};
-7
View File
@@ -105,13 +105,6 @@ export async function getAttachmentForJWT(token: string): Promise<Attachment> {
throw AuthenticationError("Invalid token");
}
// check the token is within it's expiration time
if (payload.expiresAt) {
if (new Date(payload.expiresAt) < new Date()) {
throw AuthenticationError("Expired token");
}
}
const attachmentId = payload.key.split("/")[2];
const attachment = await Attachment.findByPk(attachmentId, {
rejectOnEmpty: true,