From e314d9cbd9b289306fb129800d262c1771ecdd9f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 21 Sep 2025 21:53:25 -0700 Subject: [PATCH] [refactor] Simplify current user resolved hook implementation (#5718) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Refactored `onUserResolved` function in auth composable to use VueUse `whenever` utility instead of manual watch implementation and use `immediate` option instead of invoking manually before creating watcher. ## Changes - **What**: Replaced manual watch + immediate check pattern with [VueUse whenever](https://vueuse.org/shared/whenever/) utility in `useCurrentUser.ts:37` ## Review Focus Behavioral equivalence verification - `whenever` with `immediate: true` should maintain identical callback timing and cleanup semantics. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5718-refactor-Simplify-current-user-resolved-hook-implementation-2766d73d365081008b6de156dd78f940) by [Unito](https://www.unito.io) --- src/composables/auth/useCurrentUser.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/composables/auth/useCurrentUser.ts b/src/composables/auth/useCurrentUser.ts index 2c70be227..37b9e4866 100644 --- a/src/composables/auth/useCurrentUser.ts +++ b/src/composables/auth/useCurrentUser.ts @@ -1,4 +1,5 @@ -import { computed, watch } from 'vue' +import { whenever } from '@vueuse/core' +import { computed } from 'vue' import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions' import { t } from '@/i18n' @@ -33,19 +34,8 @@ export const useCurrentUser = () => { return null }) - const onUserResolved = (callback: (user: AuthUserInfo) => void) => { - if (resolvedUserInfo.value) { - callback(resolvedUserInfo.value) - } - - const stop = watch(resolvedUserInfo, (value) => { - if (value) { - callback(value) - } - }) - - return () => stop() - } + const onUserResolved = (callback: (user: AuthUserInfo) => void) => + whenever(resolvedUserInfo, callback, { immediate: true }) const userDisplayName = computed(() => { if (isApiKeyLogin.value) {