class Token {
constructor(tokenString, expiry) {
this.tokenString = tokenString; // The actual token string
this.expiry = expiry; // Expiration timestamp (in seconds since epoch)
}
isValid() {
const now = Math.floor(Date.now() / 1000); // Current time in seconds
return now < this.expiry; // Check if token has expired
}
getTokenString() {
return this.tokenString;
}
getExpiry() {
return this.expiry;
}
}
// Example usage:
// Create a simple token
const token = new Token("simpletoken123", Math.floor(Date.now() / 1000) + 60); // Expires in 60 seconds
// Check if the token is valid
console.log("Token is valid:", token.isValid());
// Get the token string
console.log("Token string:", token.getTokenString());
//Get the expiry time
console.log("Expiry time:", token.getExpiry());
Add your comment