mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-08 22:50:00 +08:00
not using cache if requiring fresh token
This commit is contained in:
parent
0c3e3549b0
commit
8fca782f30
2 changed files with 9 additions and 2 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue