not using cache if requiring fresh token

This commit is contained in:
Miodec 2022-09-28 00:16:45 +02:00
parent 0c3e3549b0
commit 8fca782f30
2 changed files with 9 additions and 2 deletions

View file

@ -144,7 +144,7 @@ async function authenticateWithBearerToken(
options: RequestAuthenticationOptions
): Promise<MonkeyTypes.DecodedToken> {
try {
const decodedToken = await verifyIdToken(token);
const decodedToken = await verifyIdToken(token, options.requireFreshToken);
if (options.requireFreshToken) {
const now = Date.now();

View file

@ -17,7 +17,14 @@ const tokenCache = new LRUCache<string, DecodedIdToken>({
const TOKEN_CACHE_BUFFER = 1000 * 60 * 5; // 5 minutes
export async function verifyIdToken(idToken: string): Promise<DecodedIdToken> {
export async function verifyIdToken(
idToken: string,
noCache = false
): Promise<DecodedIdToken> {
if (noCache) {
return await admin.auth().verifyIdToken(idToken, true);
}
setTokenCacheLength(tokenCache.size);
setTokenCacheSize(tokenCache.calculatedSize ?? 0);