Easy
This question is a daily question and will count towards your daily streak.
During a client meeting, your team discovers the authentication system isn't properly handling token expiration. What would be the output when testing this token validator?
1class TokenValidator {2 constructor(expirationMinutes = 60) {3 this.expirationMs = expirationMinutes * 60 * 1000;4 }56 createToken(userId) {7 return {8 userId,9 created: Date.now(),10 expires: Date.now() + this.expirationMs11 };12 }1314 isValid(token) {15 if (!token?.expires) return false;16 const now = Date.now();17 const timeLeft = token.expires - now;18 return timeLeft > 0;19 }20}2122const validator = new TokenValidator(1); // 1 minute expiration23const token = validator.createToken('user123');2425setTimeout(() => {26 console.log(validator.isValid(token));27}, 30 * 1000); // Check after 30 seconds2829setTimeout(() => {30 console.log(validator.isValid(token));31}, 90 * 1000); // Check after 90 seconds