Checking the token is expired or not using moment

PHOTO EMBED

Wed Mar 08 2023 11:10:51 GMT+0000 (Coordinated Universal Time)

Saved by @skfaizan2301 #react.js #javascript

import moment from 'moment';

const expiryDate = '03-21-2023';
const currentDate = moment();

// Parse the expiry date using Moment.js
const parsedExpiryDate = moment(expiryDate, 'MM-DD-YYYY');

// Compare the expiry date to the current date to check if the token is expired
if (parsedExpiryDate.isBefore(currentDate)) {
  console.log('Token has expired!');
} else {
  console.log('Token is still valid');
}
content_copyCOPY