Cleanup oauth tokens cache
authorChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 06:40:38 +0000 (08:40 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 06:40:38 +0000 (08:40 +0200)
server/lib/auth.ts

index 7c1dd1139b4ba9cb00a553f678d345ed7ecce485..8579bdbb44401e0f6fe0b1d4d5e82b54284a0ff8 100644 (file)
@@ -105,6 +105,14 @@ async function onExternalUserAuthenticated (options: {
     authName
   })
 
+  // Cleanup
+  const now = new Date()
+  for (const [ key, value ] of authBypassTokens) {
+    if (value.expires.getTime() < now.getTime()) {
+      authBypassTokens.delete(key)
+    }
+  }
+
   res.redirect(`/login?externalAuthToken=${bypassToken}&username=${user.username}`)
 }