Skip to content

Commit

Permalink
fix expiry date extraction of a credential
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmanos committed Jan 20, 2025
1 parent 4444c89 commit c6855da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Credentials/ExpiredRibbon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const ExpiredRibbon = ({ parsedCredential }) => {

return (
<>
{parsedCredential && CheckExpired(parsedCredential.exp ?? parsedCredential.expiry_date) &&
<div className={`absolute bottom-0 right-0 text-white text-xs py-1 px-3 rounded-tl-lg rounded-br-2xl border-t border-l border-white ${CheckExpired(parsedCredential.exp ?? parsedCredential.expiry_date) ? 'bg-red-600' : 'bg-green-500'}`}>
{parsedCredential?.beautifiedForm && CheckExpired(parsedCredential.beautifiedForm) &&
<div className={`absolute bottom-0 right-0 text-white text-xs py-1 px-3 rounded-tl-lg rounded-br-2xl border-t border-l border-white ${CheckExpired(parsedCredential.beautifiedForm) ? 'bg-red-600' : 'bg-green-500'}`}>
{t('expiredRibbon.expired')}
</div>
}
Expand Down
13 changes: 6 additions & 7 deletions src/functions/CheckExpired.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// CheckExpired.js
export function CheckExpired(expiry_date) {
if (!expiry_date) {
export function CheckExpired(data) {

if (!data.exp || typeof data.exp != 'number') {
return false;
}

const parsedExpiryDate = typeof expiry_date == 'string' ? expiry_date : new Date(expiry_date * 1000).toISOString();
const today = new Date();
const expirationDate = new Date(parsedExpiryDate);
return expirationDate < today;
const parsedExpiryDate = new Date(data.exp * 1000);
console.log("Parsed expiry date = ", parsedExpiryDate)
return parsedExpiryDate < new Date();
};

0 comments on commit c6855da

Please sign in to comment.