From 3bc885cb5303f3397fc462437dce307a2f8d1800 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Wed, 4 May 2022 14:13:51 -0700 Subject: [PATCH] Only warm up create user function once --- web/lib/firebase/users.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index e07d138c..8b8523c6 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -77,11 +77,13 @@ const CACHED_USER_KEY = 'CACHED_USER_KEY' // used to avoid weird race condition let createUserPromise: Promise | undefined = undefined +const warmUpCreateUser = _.throttle(createUser, 5000 /* ms */) + export function listenForLogin(onUser: (user: User | null) => void) { const cachedUser = localStorage.getItem(CACHED_USER_KEY) onUser(cachedUser ? JSON.parse(cachedUser) : null) - if (!cachedUser) createUser() // warm up cloud function + if (!cachedUser) warmUpCreateUser() return onAuthStateChanged(auth, async (fbUser) => { if (fbUser) {