const authCache = {};
/**
* Retrieves an authentication token from the cache.
* @param {string} token - The authentication token to retrieve.
* @returns {string | undefined} - The token if found, otherwise undefined.
*/
function getAuthToken(token) {
if (authCache.hasOwnProperty(token)) {
return authCache[token];
}
return undefined;
}
/**
* Stores an authentication token in the cache.
* @param {string} token - The authentication token to store.
* @param {any} data - Optional data associated with the token.
*/
function setAuthToken(token, data) {
authCache[token] = data;
}
/**
* Removes an authentication token from the cache.
* @param {string} token - The authentication token to remove.
*/
function removeAuthToken(token) {
delete authCache[token];
}
//Example Usage (for testing)
//setAuthToken("testToken", {user: "testUser"});
//const token = getAuthToken("testToken");
//console.log(token); //Output: {user: "testUser"}
//removeAuthToken("testToken");
//const token2 = getAuthToken("testToken");
//console.log(token2); //Output: undefined
Add your comment